标签:
<h1>上传</h1> <div>说明:只能上传word文档 且小于1M</div> <form action="scchuli.php" method="post" enctype="multipart/form-data"> <input type="file" name="file" /> <input type="submit" value="上传" /> </form>
<?php session_start(); $_SESSION["uid"]="lisi"; include("../DBDA.class.php"); $db=new DBDA(); $filename=""; //加限制条件 if($_FILES["file"]["type"]=="application/vnd.openxmlformats-officedocument.wordprocessingml.document" && $_FILES["file"]["sizs"]<1048576) { //造存储路径 $filename="./upload/".date("YmdHis").$_FILES["file"]["name"]; //转编码格式 $filename=iconv("UTF-8","gb2312",$filename); //判断文件是否存在 if(!file_exists($filename)) { //保存文件 move_uploaded_file($_FILES["file"]["tmp_name"],$filename); } } //向文件表添加一条数据 $uid=$_SESSION["uid"]; $lujing=iconv("gb2312","UTF-8",$filename); $urls="/0630wenjian/".$lujing; $times=date("Y-m-d H:i:s"); $name=$_FILES["file"]["name"]; $sql="insert into wenjian values(‘‘,‘{$uid}‘,‘{$urls}‘,‘{$times}‘,‘{$name}‘)"; $db->Query($sql,0); header("location:guanli.php");
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> </head> <?php session_start(); include("../DBDA.class.php"); $db=new DBDA(); $uid=$_SESSION["uid"]; $sql="select * from wenjian where uid=‘{$uid}‘"; $attr=$db->Query("$sql"); ?> <body> <h1>文件管理</h1> <table width="80%" border="1" cellpadding="0" cellspacing="0"> <tr> <td>上传者</td> <td>上传时间</td> <td>文件名</td> <td></td> </tr> <?php foreach($attr as $v) { $sname="select Name from user where Uid=‘{$v[1]}‘"; $name=$db->StrQuery($sname); echo "<tr> <td>{$name}</td> <td>{$v[3]}</td> <td>{$v[4]}</td> <td><a href=‘{$v[2]}‘>下载</a></td> </tr>"; } ?> </table> </body> </html>
a标签 <a></a>中href=文件路径 实现简单的下载
标签:
原文地址:http://www.cnblogs.com/hamilton/p/5631231.html