bxt0058 2014-06-04 16:11 采纳率: 0%
浏览 891

php 下载中文图片报错问题

放在不同页面中运行他会报出下载的图片不存在的错误但是我的图片存在
英文的图片名可以但是中文的图片名就报文件不存在为什么?帮忙改正一下。。。。
ShowPicture.php页面如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">



无标题文档


点击下载
点击下载

<?php
$str = urlencode("顺平.jpg");
echo "点击下载"
?>
点击下载


DownPicture.php页面如下:
<?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页面如下:
<?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);
}
?>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 YoloV5 第三方库的版本对照问题
    • ¥15 请完成下列相关问题!
    • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
    • ¥15 求daily translation(DT)偏差订正方法的代码
    • ¥15 js调用html页面需要隐藏某个按钮
    • ¥15 ads仿真结果在圆图上是怎么读数的
    • ¥20 Cotex M3的调试和程序执行方式是什么样的?
    • ¥20 java项目连接sqlserver时报ssl相关错误
    • ¥15 一道python难题3
    • ¥15 牛顿斯科特系数表表示