Home  >  Article  >  Backend Development  >  Small guestbook example of php file operation_PHP tutorial

Small guestbook example of php file operation_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 09:49:15994browse

A small guestbook example of php file operation

This article describes an example of a small guestbook for php file operation. Share it with everyone 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/"; //定义路径

$dr = opendir($path); //打开目录

while($filen = readdir($dr)) //循环读取目录中的文件

{

if($filen != "." and $filen != "..")

{

$fs = fopen($path.$filen, "r");

echo "标题:".fgets($fs)."
";

echo "作者:".fgets($fs)."
";

echo "内容:

".fread($fs, filesize($path.$filen))."
";

echo "


";

fclose($fs);

}

}

closedir($dr) //关闭目录

?>

1

2

3

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 "留言发表成功!";

echo "返回首页";

?>

4 5 6 7 8 9 10 11 12 13 14 15 16 17
Title: ".fgets($fs)."
"; echo "Author: ".fgets($fs)."
"; echo "Content:
".fread($fs, filesize($path.$filen))."
"; echo "
"; fclose($fs); } } closedir($dr) //Close the directory ?>
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 posted successfully!";<🎜> <🎜>echo "Return 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">

发表新的留言

发表新的留言

标题
作者
内容

1

2 3

45 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"> 发表新的留言

发表新的留言

标题
作者
内容

  希望本文所述对大家的php程序设计有所帮助。 http://www.bkjia.com/PHPjc/1020286.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/1020286.htmlTechArticlephp文件操作之小型留言本实例 本文实例讲述了php文件操作之小型留言本。分享给大家供大家参考。具体如下: Index.php文件如下: ? 1 2 3 4...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn