Page 1 of 1

making a .bat file in php?

Posted: Wed Nov 02, 2005 8:43 pm
by anthony88guy
I know you can make text files and what not, but i was wondering would it be possible to make a batch file?

thanks

Posted: Wed Nov 02, 2005 9:05 pm
by feyd
try it. :roll:

Posted: Wed Nov 02, 2005 9:41 pm
by josh
(yes), not only can you make ASCII files you can make binary files (.zip, .jpg, .swf, etc..)

Very Easy

Posted: Wed Nov 02, 2005 11:50 pm
by smartknightinc
feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


Hi, Just create a program for it like we write another file in php.

eg.

Code: Select all

<?php
$filename = 'test.bat';
$somecontent = "echo "harry"\n";

// Let's make sure the file exists and is writable first.
if (is_writable($filename)) {

   // In our example we're opening $filename in append mode.
   // The file pointer is at the bottom of the file hence 
   // that's where $somecontent will go when we fwrite() it.
   if (!$handle = fopen($filename, 'a')) {
         echo "Cannot open file ($filename)";
         exit;
   }

   // Write $somecontent to our opened file.
   if (fwrite($handle, $somecontent) === FALSE) {
       echo "Cannot write to file ($filename)";
       exit;
   }
   
   echo "Success, wrote ($somecontent) to file ($filename)";
   
   fclose($handle);

} else {
   echo "The file $filename is not writable";
}
?>
very easy :)
thanks


feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Posted: Thu Nov 03, 2005 6:18 am
by foobar
Yet another use who hasn't read the PHP Manual.