php文件操作之小型留言本实例

2015 年 7 月 9 日5920

本文实例讲述了php文件操作之小型留言本。分享给大家供大家参考。具体如下:

Index.php文件如下:

<?php

$path = "DB/"; //定义路径

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

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

{

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

{

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

echo "<B>标题:</B>".fgets($fs)."<BR>";

echo "<B>作者:</B>".fgets($fs)."<BR>";

echo "<B>内容:</B><PRE>".fread($fs, filesize($path.$filen))."</PRE>";

echo "<HR>";

fclose($fs);

}

}

closedir($dr) //关闭目录

?>

Post.php文件如下:

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

echo "<a href="Index.php" mce_href="Index.php">返回首页</a>";

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

"http://http://www.zjjv.com///TR/html4/loose.dtd">

<html>

<head>

<title>发表新的留言</title>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312">

</head>

<body>

<H1><p>发表新的留言</p></H1>

<form method="post" action="Post.php"> <table cellpadding="0" cellspacing="0"> <tr>

<td>标题</td>

<td><input type="text" size="50"></td> </tr> <tr>

<td>作者</td>

<td><input type="text" size="20"></td> </tr> <tr>

<td>内容</td>

<td><textarea cols="50" rows="10"></textarea></td> </tr> </table> <p> <input type="submit" value="Submit"> <input type="reset" value="Reset">

</p>

</form>

</body>

</html>

希望本文所述对大家的php程序设计有所帮助。

搜索相关文章:

(责任编辑:51自学网)

0 0