Small message book instance for PHP file operations,
This example describes the small message book for PHP file operations. Share it with you for your reference. The details are as follows:
The Index. php file is as follows:
<? Php $ path = "DB/"; // define the path $ dr = opendir ($ path); // open the directory while ($ filen = readdir ($ dr )) // cyclically read the files in the directory {if ($ filen! = "." And $ filen! = ".. ") {$ Fs = fopen ($ path. $ filen, "r"); echo "<B> title: </B> ". fgets ($ fs ). "<BR>"; echo "<B> author: </B> ". fgets ($ fs ). "<BR>"; echo "<B> content: </B> <PRE> ". fread ($ fs, filesize ($ path. $ filen )). "</PRE>"; echo "<HR>"; fclose ($ fs) ;}} closedir ($ dr) // close the directory?>
The Post. php file is as follows:
<? Php $ path = "DB/"; $ filename = "S ". date ("YmdHis "). ". dat "; $ fp = fopen ($ path. $ filename, "w"); fwrite ($ fp, $ _ POST ["title"]. "/n"); fwrite ($ fp, $ _ POST ["author"]. "/n"); fwrite ($ fp, $ _ POST ["content"]. "/n"); fclose ($ fp); echo "message published successfully! "; Echo" <a href = "Index. php" mce_href = "Index. php"> back to home </a> ";?>
<! Doctype html public "-// W3C // dtd html 4.01 Transitional // EN" "http://www.w3.org/TR/html4/loose.dtd">
I hope this article will help you with php programming.