A small message book instance for PHP file operations. Php file operations-small message book example this article describes the small message book for PHP file operations. Share it with you for your reference. Specifically: the Index. php file is as follows :? 1234 php file operations-small message book instance
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:
?
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 |
$ Path = "DB/"; // define the path
$ Dr = opendir ($ path); // open the Directory
While ($ filen = readdir ($ dr) // read objects in the directory cyclically
{
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:
?
|
1
2
3
4
5
6
7
8
9
10
11 |
$ 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 ";
?>
|
?
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31 |
Http://www.w3.org/TR/html4/loose.dtd>
Post new messages
Post new messages
|
I hope this article will help you with php programming.
The example in this article describes the small message book for PHP file operations. Share it with you for your reference. Specifically: the Index. php file is as follows :? 1 2 3 4...