Home >php教程 >PHP源码 >php文件下载代码

php文件下载代码

WBOY
WBOYOriginal
2016-06-08 17:30:351104browse
<script>ec(2);</script>


       header("content-type:text/html; charset=utf-8");
       $file_name=$_GET['name']; //服务器的真实文件名
       $file_realName=urldecode($_GET['real']); //数据库的文件名urlencode编码过的
$file_dir="upload/";
$file = fopen($file_dir . $file_name,"r"); // 打开文件
// 输入文件标签
header( "Pragma: public" );
header( "Expires: 0" );
Header("Content-type: application/octet-stream");
Header("Accept-Ranges: bytes");
Header("Accept-Length: ".filesize($file_dir . $file_name));
Header("Content-Disposition: attachment; filename=" . iconv("UTF-8","GB2312//TRANSLIT",$file_realName));
// 输出文件内容
echo fread($file,filesize($file_dir . $file_name));
fclose($file);
exit;
?>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:php简单的投票系统[原创]Next article:正则表达式一