php文件操作之小型留言本实例
网络编程 2021-07-05 09:09www.168986.cn编程入门
这篇文章主要介绍了php文件操作之小型留言本,实例分析了php基于文件实现的留言本功能,需要的朋友可以参考下
本文实例讲述了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://.w3./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程序设计有所帮助。
编程语言
- 机械手焊接机器人编程 机械手焊接设备编程
- vb数据库编程实例,vb做数据库
- tiobe世界编程语言排行榜,全球编程语言排行
- 成都java编程培训 成都it编程培训中心
- 编程基础培训,编程基础知识培训
- flash游戏编程基础教程,flash游戏开发教程
- 不会英语能学编程吗 不会英语可以学程序员吗
- 爱心代码编程C语言 爱心代码编程c语言公式
- c语言编程学习入门 c语言编程快速入门
- 西门子plc编程培训 西门子plc编程培训班
- 哪里可以学编程 台州哪里可以学编程
- 少儿编程哪个好 少儿编程哪个品牌好
- 编程是什么意思,图形编程是什么意思
- c语言编程软件下载,c语言编程软件在哪下载
- java编程软件下载,java编程下载手机版
- ug编程培训学校,ug编程培训教程