<?php
//对该函数的说明
/*
参数说明:
1.file_name 文件名
2.file_sub_dir 下载文件子路径 "/XXX/XXX/"
*/
function down_file($file_name,$file_sub_path){
//$file_name=iconv("utf-8","gb2312",$file_name);
$file_path=$_SERVER['DOCUMENT_ROOT'].$file_sub_path.$file_name;
if (!file_exists($file_path)) {
echo "文件不存在";
return;
}
$fp=fopen($file_path,"r");
$file_size=filesize($file_path);
header("Content-type:application/octet-stream");
header("Accept-Ranges:bytes");
header("Accept-Length:$file_size");
header("Content-Disposition:attachment;filename=".$file_name);
//echo $file_size;
$buffer=1024;
while(!feof($fp)){
$file_data=fread($fp, $buffer);
echo $file_data;
}
fclose($fp);
}
down_file("loginlogo1.png","/images/");
?>
PHP--封装一个下载图片的方法
最新推荐文章于 2021-03-21 11:14:29 发布