Batch files are great

Sort of… Remember DOS? and .BAT files? You can write a PHP program that, to the browser that downloads it, looks and tastes [1] like a batch file with whatever code you want [2] in there.

As a web developer, I wanted to have an [EDIT] link on pages on my development server that would call Dreamweaver to open the file. If I saw something wrong with a page I used to have to: find & click Dreamweaver icon, select the site on the left (wait several seconds for it to update the cached files), find the file (possibly nested deeply within the site) and double-click on it. With the help of a batch file, with a couple quick clicks I’d see it in front of me.

The next nice web design feature would be to open a page quickly in another other browser (instead of copying the URL from the address bar, clicking the new browser icon, selecting the new browser’s address bar, pasting and hitting [enter].)

But you could also use them to open arbitrary applications, like mp3 players…

[1] For Windows to run the batch, the browser must save the PHP file with the .BAT extension, so you have to save your PHP script on the webserver with that extension, then configure the server to parse the BAT file as a PHP file. The PHP script has to send a “Content-type: application/x-msdownload” header in order for the browser to know to hand it to Windows to execute.

[2] Warning! Never run a .BAT file/link from an untrusted source. Batch files can do anything, like deleting important files or running viruses.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.