无为清净楼资源网 Design By www.qnjia.com
本文实例为大家分享了PHP实现文件上传与下载的具体代码,供大家参考,具体内容如下
主页index.php
<html> <head> <title>图片操作</title> <style> #contains { width: 500px; margin: 0 auto; text-align: center; color: #0F0; } th { background: #ccc; } td { width: 150px; height: 50px; text-align: center; } </style> </head> <body> <div id="contains"> <h2>图片上传和下载</h2> <!----------------文件上传表单-------------> <form action="doupload.php" method="post" enctype="multipart/form-data"> <input type="hidden" value="10000000" /> <!---避免上传后发现文件过大---> <input type="file" name="pic"/> <input type="submit" value="上传"/> </form> <!---------------------------------------> <table width="500" border="0"> <tr> <th>序号</th><th>图片</th><th>添加时间</th><th>操作</th> </tr> <"./imgs"); //2.遍历目录 $i = 0; $color = "#ff0"; while ($f = readdir($dir)){ //$f代表这每个文件的名字 if ($f == '.' || $f == "..") continue; //处理特殊隐藏的文件 $i++; if ($i % 2 == 0) $color = "#ccc"; else $color = "#ffa"; echo "<tr bgcolor=$color>"; echo "<td>{$i}</td>"; echo "<td><img src='./imgs/{$f}' width='150' height='50'/></td>"; echo "<td>".date("Y-m-d", filectime('./imgs/'.$f))."</td>"; echo "<td><a href='./imgs/{$f}'>查看</a> <a href='download.php"; echo "</tr>"; // echo $f." "; } "htmlcode"><"<pre>"; var_dump($_FILES); echo "</pre>";*/ //1.获取上传文件信息 $upfile = $_FILES["pic"]; $path = "./imgs/"; //2、过滤错误信息 if ($upfile["error"] > 0) { die("上传文件错误"); } //3、本次上传文件的大小过滤 if ($upfile["size"] > 10000000) { die("上传文件超出限制"); } //4、处理文件类型 $typelist = array("jpeg","jpg","png","gif"); $arr = explode(".", basename($upfile['name'])); //以'.'分割字符串为数组 $bz = array_pop($arr); //获取文件的后缀名 if (!in_array($bz, $typelist)) { //如果给定的值 value 存在于数组 array 中则返回 true die("上传文件类型非法!".$upfile["type"]); } //5、设置相同文件的名字不同 $newfile = date("YmdHis").rand(100, 999).".".$bz; // if (is_uploaded_file($upfile["tmp_name"])) { //判断文件是否是通过post上传 //执行文件上传 if (move_uploaded_file($upfile["tmp_name"], $path.$newfile)) {//将上传的文件保存在新位置 echo "上传成功!"; echo "<a href='index.php'>浏览</a>"; }else { die("上传失败"); } } "htmlcode"><"./imgs/".$_GET["name"]; // echo $file; //2.重设响应类型 $info = getimagesize($file); //获取文件大小 // var_dump($info); header("Content-Type:".$info["mime"]); //3.执行下载文件名 header("Content-Disposition:attachment;filename=".$_GET["name"]); //4.指定文件大小 header("Content-Length:".filesize($file)); //5.响应内容 readfile($file); "text-align: center">以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
无为清净楼资源网 Design By www.qnjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
无为清净楼资源网 Design By www.qnjia.com
暂无评论...
更新日志
2024年09月25日
2024年09月25日
- 黄心懋1991-轻忧郁【滚石】【WAV+CUE】
- 群星.2000-大地金曲世纪回顾2CD【大地】【WAV+CUE】
- 王菲.1996-浮躁(2024环球MQA-UHQCD限量版)【环球】【WAV+CUE】
- 群星.2022-传家电视剧原声带【东阳欢娱】【FLAC分轨】
- 《摇滚教父 伍佰黄金精选 2CD》 [WAV+CUE][1GB]
- 《凤凰传奇 我从草原来》[WAV/分轨][400MB]
- 《叶倩文 真心真意过一生》[WAV+CUE][400MB]
- 潘越云.1985-世间女子(滚石25周年经典复刻版)【滚石】【WAV+CUE】
- 陈柏宇.2009-CANT.BE.HALF【SONY】【WAV+CUE】
- 李明依.1989-小女生【滚石】【WAV+CUE】
- 《李荣浩 新时代创作新人王》[WAV分轨][310MB]
- 《黑鸭子与马头琴 史上最动听草原音乐》[WAV+CUE][320MB]
- 《汽车发烧音乐精选CD18》[FLAC+CUE][7.1G]
- 郑希怡.2004-Perfect.Date【英皇娱乐】【FLAC分轨】
- 群星.1994-宝丽金超级孖宝2CD【宝丽金】【WAV+CUE】