<?php
$hua = $_SERVER['HTTP_USER_AGENT'];
$showname = "鳄鱼头上一只蝴蝶.jpg";
$encode_zh = urlencode($showname);
$encode_zh = str_replace("+","%20",$encode_zh);
$on_disk = "1.jpg";
$file = fopen($on_disk,"r"); // 打开文件
//ob_end_clean();
header("Content-type: application/octet-stream");
header("Accept-Ranges: bytes");
header("Accept-Length: ".filesize($on_disk));
if (preg_match("/MSIE/",$hua))
{
header('Content-Disposition: attachment; filename="'.$encode_zh);
}elseif (preg_match("/Firefox/",$hua))
{
header('Content-Disposition: attachment; filename*="utf8/'/''.$showname);
}else
{
header('Content-Disposition: attachment; filename="'.$showname.'"');
}
$download= fread($file, filesize($on_disk));
echo $download;
fclose($file);
?>
php 文件下载-文件中文名称显示乱码处理
最新推荐文章于 2021-03-09 20:06:39 发布