您好,欢迎访问一九零五行业门户网

PHP解决浏览器 上载文件 中文名称乱码有关问题-兼容大多浏览器

php解决浏览器 下载文件 中文名称乱码问题--兼容大多浏览器
function sendfile($serverpath, $filename,$charset = 'utf-8', $mimetype = 'application/octet-stream'){ // 文件名乱码问题 if (preg_match(/msie/, $_server[http_user_agent])) { $filename = urlencode($filename); $filename = str_replace(+, %20, $filename);// 替换空格 $attachmentheader = content-disposition: attachment; filename=\{$filename}\; charset={$charset}; } else if (preg_match(/firefox/, $_server[http_user_agent])) { $attachmentheader = 'content-disposition: attachment; filename*=utf8\'\'' . $filename. '' ; } else { $attachmentheader = content-disposition: attachment; filename=\{$filename}\; charset={$charset}; } $filesize = filesize($serverpath); //header(pragma: public); header(expires: 0); header(cache-control: must-revalidate, post-check=0, pre-check=0); header(content-type: application/force-download); header(content-type: {$mimetype}); header($attachmentheader); header('pragma: cache'); header('cache-control: public, must-revalidate, max-age=0'); header(content-length: {$filesize}); readfile($serverpath); exit;}
?
其它类似信息

推荐信息