Jump to: navigation, search

PHP, Filesystems and File I/O

632 bytes added, 19:25, 4 June 2007
Writing to a File using PHP
OR die ("Can't open file\n");
$result = fwrite ($fileHandle, "This line of text was written by PHP\n"); if ($result){ echo "Data written successfully.<br>";} else { echo "Data write failed.<br>";} 
After running the above script you should find a file exists on your server containing the line <tt>This line of text was written by PHP</tt>.
It is also possible to read the contents of an enter file with the ''readfile'' function. This function reads the entire contents of a file and outputs that content. Assumign you don't need to do anything but output the contents of a file then 'readfile'' is an easy solution because it does all the work for you. You do not need to open the file, read the data, close the file and display the data. All you need to do is call ''readfile'' and it does the rest.
== Moving, Copying and Deleting Files with PHP ==
== Reading From a File using PHP ==

Navigation menu