Small message book instance for PHP file operations

Source: Internet
Author: User
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. if you need it, you can refer to the example below to describe 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.