This article mainly introduces the small message book for php file operations. The example analyzes the message book function implemented by php Based on files. For more information, see
This article mainly introduces the small message book for php file operations. The example analyzes the message book function implemented by php Based on files. For more information, see
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"Title:". Fgets ($ fs )."
"; Echo"Author:". Fgets ($ fs )."
"; Echo"Content:
".fread($fs, filesize($path.$filen))."
"; Echo" "; 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" back to homepage ";?>
Post New Messages
Post New Messages
I hope this article will help you with php programming.
,