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.
Related
I'm a frontend developer and I'm facing with a problem.
Whenever I'm building a website, I'm using PHP to include the template files, so I get a redundant code.
But when I want to generate this file into an HTML file I open up the PHP file in the browser to copy/paste the code to an HTML file.
How can I make this process to be way much faster, or how could I avoid to do these things manually? Maybe there is a program to do this or something?
You can use a recursive wget.
Say your webserver runs on your localhost, you can run:
wget -r -k localhost
Be careful: wgetdoes not perform a search on which pages are available, it simply looks at links (the <a> tags) and will capture these as well. As long as everything is reachable from the index page (not necessarily on the index page), it will be downloaded.
wget is a linux program, but I guess there is a Windows application with the same name/options as well... As #rkbvkleef points out, it's part of the MinGW package.
Basically your php file (which runs on server, could be local server) contains or generates your HTML code to present on browser. You can simply write HTML code out of tags in a php file and it will work. Or if you want to generate some HTML based on some conditions you are checking inside php or using some variables in php then you can use echo function. It will display whatever string you echo on your webpage.
<?php
$name = "Murtaza";
echo("<h1>Hello ".$name."</h1>");
?>
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.
I'm writing a document managment system. One of the features that has been requested is that users be able to cause the system to copy certain files to a location that both the users and php have access to. From here the user will be able to directly edit the files. What needs to happen is that the edited file must be automatically saved to the document management system as a new version. My question is with regards to this last point.
I have a page that allows the user to view all versions of a specific file. I was thinking that what would be cool would be to have things that when this page is accessed by anyone then php checks if there is an associated file that was edited and is now closed and simply move it to the right place and give it version info. Would this be possible? For example if a user is editing a file using MS Word, would php be able to know if that file is in use? If yes, how?
Another alternative is to just grab all files that were edited periodically (during the witching hour, for example) and also have a handy 'synchronise' button that users can click to signal that they are done.
here's some stuff I've tried:
flock: i thought it mich return false for files that are in use. mistaken
fstat: doesn't return anything useful as far as I can tell
unlink: I thought I might make a copy of the file then try unlink the original(user edited one). it turns out unlink works on stuff that is open
any ideas?
Also, it needs to work on windows and linux...
Here's some clarification for them what need: if andrew were to click the 'edit' button corresponding to a word file then the word file would be copied to some location. Andrew would then edit it using MS word, save his changes (possible more than once) and close it. That is all I want Andrew to do. I want my code to see that the file is closed then do stuff with it
You can create a file "filename.lock" (or "filename.lck") for each file open.
And you delete the file "filename.lock" (or "filename.lck") when is unlock.
And you can check if file is locked when the file "filename.lock" (or "filename.lck") exists.
If you're running under unix OS, you can implement a strategy like that:
Write a bash script like this lsof | grep /absolute/path/to/file.txt
You can also parameterize that
Recall that script from php
<?php
$result=shell_exec("myScriptPath");
echo($result);
?>
Remember that bash script will return status 0 if no one has file open, 256 (1) otherwise
I have designed an online editor with which a user can create files and folders on the server. Suppose a user creates the below files and folders.
/docs/abc.txt
/docs/def.txt
/docs/work/assignment.txt
I want to write a PHP script to combine the files into a single ZIP file so that it makes it easier for the user to download them with one click.
The only purpose is that I should get a single file with the directory hierarchy maintained which the user can download and uncompress on his system to get the original files and directory structure back. I don't care even if the ZIP file is not compressed.
Note that I am using a shared server and do not have access to execute external commands.
ZipArchive class is what you need. Using this you can add directories and file to an archive.
This is a common requirement and has been solved. Try and check out this class: http://www.phpclasses.org/browse/package/2322.html
More tutorials at:
http://davidwalsh.name/create-zip-php <-- this has a similar example if you scroll down
http://www.w3schools.com/php/php_ref_zip.asp
Assuming you have permission to execute an external command, you could use exec to run an external command-line capable ZIP program such as 7-Zip.
Is there any trick to run .PHP files in windows XP from any folder by double clicking like HTML file ?
I use XAMPP but in this we need to put files ina special htdocs folder. I want to run file from any folder, desktop by double clicking.
After searching a lot I found a easy way to do this
PHPScriptNet – Great portable application for those who learning PHP. PHPScriptNet can run your PHP script anywhere in Windows machine without installing PHP or any webserver.
http://www.digitalcoding.com/free-software/webmaster-tools/PHPScriptNet-Portable-application-to-run-PHP-Script-from-windows.html
There is a significant difference in viewing HTML files vs. PHP files:
HTML files are static files interpreted by the browser. When you open them, the PATH to the HTML file is passes as an argument to the default browser which interprets and displays the file.
PHP files on the other hand are required to be interpreted by a PHP interpreter (XAMPP, in your case) before the resulting HTML is rendered by a browser. In this case, the local file PATH would have to be translated to the corresponding local URL, then sent to the browser.
Sample Solution
You could write a simple script that replaces '/var/www/' with 'http://localhost:8888/' (with a regular expression, for example) and passes that to the browser. Then, associate PHP files with your script.
PHP comes with a command line interface interpreter called php.exe (in Windows). This can be found in the root of your PHP installation directory.
You will need to associate .php files with this interpreter. That is, go into Tools -> Folder Options -> File types, and register php.exe -f "%1" as the application for the .php file type.
That said, it's not very typical to want to 'run' a PHP file by double-clicking it - not many people would use PHP the same way they'd use, for example, batch files or shell scripts - PHP is much better suited to generating web pages, ie using it in a web server. Chances are, running PHP outside of a web server is not what you really want to do here. For example, the PHP file will run within a command window and its output will be plain text, and if you want to see its output your script will need to pause or wait for input from standard input itself after terminating.
More information at Using PHP from the command line