Mega Code Archive

 
Categories / Php / File Directory
 

Writing and Appending to a File

<html> <head> <title>Writing and Appending to a File</title> </head> <body> <div> <?php $filename = "data.txt"; print "Writing to $filename<br/>"; $fp = fopen ( $filename, "w" ) or die ( "Couldn't open $filename" ); fwrite ( $fp, "Hello world\n" ); fclose ( $fp ); print "Appending to $filename<br/>"; $fp = fopen ( $filename, "a" ) or die ( "Couldn't open $filename" ); fputs ( $fp, "And another thing\n" ); fclose ( $fp ); ?> </div> </body> </html>