《PHP編程:php文件操作之小型留言本實例》要點:
本文介紹了PHP編程:php文件操作之小型留言本實例,希望對您有用。如果有疑問,可以聯系我們。
PHP教程本文實例講述了php文件操作之小型留言本.分享給大家供大家參考.具體如下:
PHP教程Index.php文件如下:
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) //關閉目錄
?>
PHP教程Post.php文件如下:
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>";
?>
PHP教程
<!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>
PHP教程希望本文所述對大家的php程序設計有所幫助.
維易PHP培訓學院每天發布《PHP編程:php文件操作之小型留言本實例》等實戰技能,PHP、MYSQL、LINUX、APP、JS,CSS全面培養人才。