Small guestbook example of php file operation, _PHP tutorial

WBOY
Release: 2016-07-13 09:49:33
Original
853 people have browsed it

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:

Index.php file is as follows:

<&#63;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))."
"; echo "
"; fclose($fs); } } closedir($dr) //关闭目录 ?>
Copy after login

Post.php file is as follows:

<&#63;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>"; 
&#63;> 

Copy after login
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>发表新的留言</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<H1><p align="center">发表新的留言</p></H1>
<form name="form1" method="post" action="Post.php">
 <table width="500" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
   <td>标题</td>
   <td><input name="title" type="text" id="title" size="50"></td>
  </tr>
  <tr>
   <td>作者</td>
   <td><input name="author" type="text" id="author" size="20"></td>
  </tr>
  <tr>
   <td>内容</td>
   <td><textarea name="content" cols="50" rows="10" id="content"></textarea></td>
  </tr>
 </table>
 <p align="center">
  <input type="submit" value="Submit">
  <input type="reset" value="Reset">
</p>
</form>
</body>
</html>

Copy after login

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1019440.htmlTechArticleA 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: php $p...
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template