当前位置: 首页 > 图文教程 > 网络编程 > PHP > 建立文件交换功能的脚本(一)

PHP
MYSQL版本大于4.1问题 - PHPchina
怎么让用户点击一个连接后,把一个图片另存了 - PHPchina
武汉10月15日Phper聚会召集!!! - PHPchina
php如果不等待exec执行的程序创建的子进程? - PHPchina
哪位知道DISCUZ处理防SQL注入的代码是哪部分 - PHPchina
求教!我实在不知道哪里问题,在线等ing - PHPchina
怎样结束用户某一进程 - PHPchina
比对用户名密码能不能这样写? - PHPchina
求助:如何在PHP+mysql中实现数据备份? - PHPchina
大家看看这个配置对吗 - PHPchina
如何禁止require当前文件 - PHPchina
无法将回调函数放在类中? - PHPchina
村里 PHP代码高亮是怎么实现的? - PHPchina
apache安装后.服务里没有apache2这个服务! - PHPchina
请教一个小问题 - PHPchina
config.php里面是不是应该把多数参数设置为常量而不是变量? - PHPchina
请教高手一个问题 - PHPchina
如何让百度收录我的网站 ?? - PHPchina
谁能给个注入的简单语句? - PHPchina
求PHP站内搜索思路 - PHPchina

PHP 中的 建立文件交换功能的脚本(一)


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-13   浏览: 75 ::
收藏到网摘: n/a

因为工作的原因需要在局域网上安装一个文件交换的东西,也可以作成一个文件上下载的功能块。
用的是php,mysql,apache现将程序编写过程贴出来,因为作这个参考来oso的一些文章,也算是一个补充,
也表达我对前辈们的敬意。
准备工作在你的mysql的yourdatabase库中建一个表upfile
/*上传文件表
CREATE TABLE upfile (
id TINYINT (8) not null AUTO_INCREMENT, //文件的id号
filename VARCHAR (80) not null, //文件名
fileshow VARCHAR (80) not null, //文件说明
date DATE not null, //上传日期
uploader VARCHAR (40) not null, //上传者签名
type VARCHAR (40) not null, //文件类型(人为定义)
PRIMARY KEY (id)
)
*/
//这是该程序的主页面,用来显示上载的文件。
//index.php
<html>
<body bgcolor="#FFFFFF">
<head>
<title>文件交换</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>

<div align="center">
<table width="500" border="0" cellspacing="0" cellpadding="0" height="25">
<tr>
<td height="25">
<div align="center">文件交换区</div>
</td>
</tr>
</table>
<table width="600" border="0" cellspacing="0" cellpadding="0" height="20">
<tr>
<td height="25" width="75">
<div align="center"><a href="upload.php">上载文件</a></div>
</td>
</tr>
</table>
<table width="600" border="0" cellspacing="0" cellpadding="0" height="79">
<tr valign="top">
<td>
<div align="center"><?
$db=mysql_connect("$hostname","$user","$password")or die("无法连接数据库"); //连接书库库
mysql_select_db("yourdatabse",$db) or die("无法打开数据库");
$sql="select * from upfile";
$result=mysql_query($sql);
if ($myrow = mysql_fetch_array($result))
{
echo "<table border=1 >\n";
echo "<tr><td>文件名</td><td>上传日期</td><td>上传者</td><td>文件说明</td><td>文件类型</td></tr>\n";
do
{
printf("<tr><td><a href=\"../file/%s\">%s</a></td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>\n",$myrow["filename"],$myrow["filename"],$myrow["date"],$myrow["uploader"],$myrow["fileshow"],$myrow["type"]);
}
//把所有的文件都列出来提供下载。
while ($myrow = mysql_fetch_array($result));
echo "</table></p>\n";
}
else
{
echo "文件交换区没有文件<br><a href='index.php'>返回</a>";
}
?></div>
</td>
</tr>
</table>
</div>
</body>
</html>