php文件操作之小型留言本實(shí)例
更新時(shí)間:2015年06月20日 10:47:38 作者:zhuzhao
這篇文章主要介紹了php文件操作之小型留言本,實(shí)例分析了php基于文件實(shí)現(xiàn)的留言本功能,需要的朋友可以參考下
本文實(shí)例講述了php文件操作之小型留言本。分享給大家供大家參考。具體如下:
Index.php文件如下:
<?php $path = "DB/"; //定義路徑 $dr = opendir($path); //打開目錄 while($filen = readdir($dr)) //循環(huán)讀取目錄中的文件 { if($filen != "." and $filen != "..") { $fs = fopen($path.$filen, "r"); echo "<B>標(biāo)題:</B>".fgets($fs)."<BR>"; echo "<B>作者:</B>".fgets($fs)."<BR>"; echo "<B>內(nèi)容:</B><PRE>".fread($fs, filesize($path.$filen))."</PRE>"; echo "<HR>"; fclose($fs); } } closedir($dr) //關(guān)閉目錄 ?>
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 "留言發(fā)表成功!"; echo "<a href="Index.php" mce_href="Index.php">返回首頁</a>"; ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>發(fā)表新的留言</title> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> </head> <body> <H1><p align="center">發(fā)表新的留言</p></H1> <form name="form1" method="post" action="Post.php"> <table width="500" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td>標(biāo)題</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>內(nèi)容</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>
希望本文所述對(duì)大家的php程序設(shè)計(jì)有所幫助。
相關(guān)文章
php實(shí)現(xiàn)比較全的數(shù)據(jù)庫操作類
這篇文章主要介紹了php實(shí)現(xiàn)比較全的數(shù)據(jù)庫操作類,可實(shí)現(xiàn)基本的數(shù)據(jù)庫連接、執(zhí)行SQL語句及錯(cuò)誤提示等相關(guān)技巧,需要的朋友可以參考下2015-06-06PHP實(shí)現(xiàn)簡單鑒權(quán)的示例代碼
這篇文章主要為大家詳細(xì)介紹了php如何通過在header增加key,sign,timestamp來實(shí)現(xiàn)鑒權(quán),文中的示例代碼講解詳細(xì),需要的小伙伴可以參考下2023-12-12編譯php 5.2.14+fpm+memcached(具體操作詳解)
本篇文章是對(duì)編譯php5.2.14+fpm+memcached的具體操作進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-06-06關(guān)于PHP中協(xié)程和阻塞的一些理解與思考
這篇文章主要給大家介紹了關(guān)于PHP中協(xié)程和阻塞的一些理解與思考,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用PHP具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面跟著小編來一起學(xué)習(xí)學(xué)習(xí)吧。2017-08-08