Batch script to download and save XLS file to directory - php

I am trying to write some batch script to download and save an XLS file from a URL. I am able to down load the file by using
#ECHO OFF
start /d "C:\Program Files\Internet Explorer" IEXPLORE.EXE url link
exit
I would now like to save these files to a folder or directory.
Any help anyone could provide here would be greatly appreciated.

There are at least two ways to do it.
Like Buddy suggested, use a command-line downloader, for example wget.
Under Linux, you can run PHP directly (even without a webserver). See PHP: Command Line PHP on Microsoft Windows in PHP manual.
Don't run a browser, or - even worse - IE, just to run a PHP script.

Related

How to use tesseract ocr with php from any location

I have installed tesseract in C:\Program Files (x86)\Tesseract-OCR. In command prompt if I am executing with tesseract 123.png sample, then it works. But I can not use tesseract with php. I have tried many libraries and codes for the same.
Someone could help me on this please?
If you needs to use Tesseract in php code, the way to do this is using the http://php.net/manual/en/function.exec.php or http://php.net/manual/en/function.shell-exec.php functions, both allow you to execute bash codes like in "command prompt", but you needs to have more attention to use that, this open several security issues because the client input data sometimes is malicious. Hope it helps!
A working examples:
exec("tesseract C:/your/path/file.png C:/output/file");
Another thing, in part C:/output/file, you don't need to put .txt in output path, tesseract always do the output as .txt file extension.
If the Tesseract is not present on "Environment Variables" the solution is to pass the full executable file path:
shell_exec('"C:/Program Files (x86)/Tesseract-OCR/tesseract.exe" C:/path/to/image C:/output/path/')

Wget download file using PHP exec

Is it possible to download a file using Wget? I want download that file into my default browser's download directory.
It's possible, but it wouldn't achieve the effect you desire.
Running wget would cause the file to be downloaded to the server (which is something you'd be better off using the cURL library for instead of shelling out to an external binary).
If you want the browser to download it, then you need to output the file from PHP, not save it to a file on the server.
Try something like this :
shell_exec('wget -P path_to_default_download_directory google.com');

How to create a shortcut to run PHP code in Windows?

I wrote some PHP to generate a single PDF file with multiple pages based on input from a Comma Seperated Values (.csv) file.
Someone who is not familiar with programming will be running the PHP very often to generate the PDF file. That person will be responsible for changing the CSV file before generating it.
I need to know how I can provide him/her a shortcut in Windows so that when he/she click it, the PHP should execute and produce the PDF file in a hardcoded path.
You can create an shortcut on file itself, or executive php bin. Check Command Line PHP on Microsoft Windows.
Just create shortcut with C:\PHP5\php.exe -f "C:\PHP Scripts\script.php" -- -arg1 -arg2 -arg3, but it will be depended on locations. So you could create association with php files and just create shortcut to your script.
Or you could launch web-server (php web-server) and put link to your script to favorites in browser.
Just create a shortcut to the page, e.g.
http://www.example.com/mypdf.php
You can even open the link with a specific browser by typing one of these as the shortcut location:
chrome http://www.example.com/mypdf.php
firefox http://www.example.com/mypdf.php
iexplore http://www.example.com/mypdf.php
Alternatively, if you're indeed running PHP as CLI-only, see #sectus' answer.

Extracting self-extracting exe archive via php

I have a problem. I have the service which is giving me .exe file which they claim is in fact zip archive. A self-extracting archive.
Problem is that I am downloading that with my app (php) to server and need to extract it there witout downloading to local computer.
I have tried download .exe file to local computer - it is self extracting on windows to /temp dir and than self launching FLASH player.
$zip = zip_open($myfile); gives in print_r($zip): 1
zip->open gives no results either.
change .exe to .zip doesn't let winzip or other kind of un-packer on windows to open it - .exe cannot be opened by winzip too.
Now I have no idea how to deal with it. If anybody can advise please.
Try to execute the program as an executable with the system command
Executing files from an external source you don't trust 100% is never a good idea.
The info-zip version of zip allows you to remove the SFX stub from a self-extracting zip file (with the -J flag) converting it back into a normal zip file.
Source code is freely available.
Making a self-extracting zip file is a matter of prepending a zip file with the SFX binary code, then appending the size of the binary stub to the resulting file - but I'm not sure how the data is represented - but a bit of reverse-engineering the available code should make this clear.
Well... if your PHP server is Windows you shouldn't have a problem doing it as a system command. Otherwise, it's a little more tricky. I hear that the unzip system command will unzip self-extracting zip files, but I don't have access to a Linux box at the moment to try it out.
If you're on shared hosting, chances are you can't do it.
Well if you think after executing the exe file, it will extract its content, then you can use exec function to run the .exe files like the one below:
exec("d:\\example\\php\_exe\\1436.exe");
and also you can use system function to run external programs as well.
And also if you wonder what's the difference:
PHP - exec() vs system() vs passthru()

PHP script can't open a file when called from a perl script

I have an interesting situation where I have a perl watcher script (using Linux::Inotify2) watch for files to be dropped in a certain directory, then hand them off to a PHP script for processing. The watched directory and the files in it are not owned by the user the watcher script is running under, but the entire directory tree the files are being dumped in are rwxr-xr-x and the file is world readable.
Here's my delemma. The PHP script cannot open a file handle on the file passed to it when called from the perl script using system(), exec() or ``. However, the PHP script can open a file handle on the same file when the script is run manually from the command-line using the same effective user.
Anyone have any ideas why this would be the case?
Your fopen() calls probably rely on relative paths that break when the working directory change.

Categories