建立文件交换功能的脚本(一)
程序员文章站
2022-07-02 20:51:05
因为工作的原因需要在局域网上安装一个文件交换的东西,也可以作成一个文件上下载的功能块。 用的是php,mysql,apache现将程序编写过程贴出来,因为作这个参考来oso...
因为工作的原因需要在局域网上安装一个文件交换的东西,也可以作成一个文件上下载的功能块。
用的是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>
用的是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>
推荐阅读
-
Shell中调用、引用、包含另一个脚本文件的三种方法
-
sed删除文件中的一行内容的脚本代码
-
一个监控LINUX目录和文件变化的Shell脚本分享
-
使用python制作一个为hex文件增加版本号的脚本实例
-
推荐一款简单好用、功能强大的服务器共享文件管理软件、共享文件管理免客户端的软件
-
Shell脚本中调用、引用、包含另外一个脚本文件的两种方法
-
mybatis 的 dao 接口跟 xml 文件里面的 sql 是如何建立关系的?一步步解析
-
python day 14: 作业:开发一个能够多用户上传文件的FTP脚本
-
Shell脚本实现删除一年前文件功能分享
-
利用Shell脚本循环读取文件中每一行的方法详解