本文实例讲述了php文件操作之小型留言本。分享给大家供大家参考。具体如下:
Index.php文件如下:
?
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) //关闭目录 ?> |
Post.php文件如下:
?
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 "返回首页"; ?> |
?
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 |
/p> "http://www.w3.org/TR/html4/loose.dtd"> |