php下载中文图片报错问题
时间:2021-07-01 10:21:17
帮助过:5人阅读
php
放在不同页面中运行他会报出下载的图片不存在的错误但是我的图片存在
英文的图片名可以但是中文的图片名就报文件不存在为什么?帮忙改正一下。。。。
ShowPicture.php页面如下:
无标题文档
点击下载
点击下载
$str = urlencode("顺平.jpg");
echo "点击下载"
?>
点击下载
DownPicture.php页面如下:
header("Expires: -1");
header("Cache-Control: no_cache");
header("Pragma: no-cache");
header("Content-Type: text/html; charset=utf-8");
require 'class/fileDown.class.php';
$name=urldecode($_REQUEST["name"]);
//echo $name;
down_file($name,"/MianXiangDuixiang/down/");
?>
fileDown.class.php页面如下:
header("Expires: -1");
header("Cache-Control: no_cache");
header("Pragma: no-cache");
header("Content-Type: text/html; charset=utf-8");
function down_file($file_name,$file_sub_dir)
{
$file_name=iconv("gb2312","GBK",$file_name);
$file_path = $_SERVER['DOCUMENT_ROOT'].$file_sub_dir.$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);
$buffer = 1024;
$file_count = 0;
while(!feof($fp) && ($file_size-$file_count>0))
{
$file_data = fread($fp,$buffer);
$file_count+=$buffer;
echo $file_data;
}
fclose($fp);
}
?>