php ie下载文件名乱码怎么办-PHP问题

资源魔 56 0

php ie下载文件名乱码的处理方法:一、经过header办法处理乱码;二、经过“function remote_filesize($uri,$user='',$pw='') {...}”等办法处理乱码。

保举:《PHP视频教程》

php文件下载IE文件名乱码成绩

不断用chrome阅读器,没发现成绩。明天用ie6,发现文件下载时文件名乱码,ie下迅雷下载文件名也是乱码。网上查了下说正在ie下需求应用urlencode编码一下,我试了下

header('Content-Disposition: attachment; filename='. rawurlencode($file_name);后果用ie下载仍是乱码。php文件自身是gbk/gb2312编码,于是我先将$file_name转换成utf-8编码再进行urlencode

header('Content-Disposition: attachment; filename='. rawurlencode(iconv("GBK","UTF-8",$file_name)));这样应用ie下载就没成绩了,莫非urlencode只能对utf-8进行本义编码?

另有就是猎取近程文件的巨细成绩,php中的filesize函数只能对内陆文件进行解决,解决近程文件会失败并收回一条正告,而且正在windows平台传入的参数必需是gbk/gb2312编码,应用utf-8编码将无奈拜访零碎中的资本。

正在网上找了四种猎取近程文件巨细的办法,多谢长辈们的分享,记载一下:

办法一:header

<?php get_headers($url,true); //前往后果 Array ( [0] => HTTP/1.1 200 OK [Date] => Sat, 29 May 2004 12:28:14 GMT [Server] => Apache/1.3.27 (Unix) (Red-Hat/Linux) [Last-Modified] => Wed, 08 Jan 2003 23:11:55 GMT [ETag] => "3f80f-1b6-3e1cb03b" [Accept-Ranges] => bytes [Content-Length] => 438 [Connection] => close [Content-Type] => text/html ) ?>

这里能够依据Content-Length间接猎取巨细了。

办法二:curl

function remote_filesize($uri,$user='',$pw='') { // start output buffering ob_start(); // initialize curl with given uri $ch = curl_init($uri); // make sure we get the header curl_setopt($ch, CURLOPT_HEADER, 1); // make it a http HEAD request curl_setopt($ch, CURLOPT_NOBODY, 1); // if auth is needed, do it here if (!emptyempty($user) && !emptyempty($pw)) { $headers = array('Authorization: Basic ' . base64_encode($user.':'.$pw)); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); } $okay = curl_exec($ch); curl_close($ch); // get the output buffer $head = ob_get_contents(); // clean the output buffer and return to previous // buffer settings ob_end_clean(); echo '<br>head-->'.$head.'<----end <br>'; // gets you the numeric value from the Content-Length // field in the http header $regex = '/Content-Length:\s([0-9].+?)\s/'; $count = preg_match($regex, $head, $matches); // if there was a Content-Length field, its value // will now be in $matches[1] if (isset($matches[1])) { $size = $matches[1]; } else { $size = 'unknown'; } //$last=round($size/(1024*1024),3); //return $last.' MB'; return $size; } 办法三:fsock
function getFileSize($url) { $url = parse_url($url); if($fp = @fsockopen($url['host'],emptyempty($url['port'])?80:$url['port'],$error)) { fputs($fp,"GET ".(emptyempty($url['path'])?'/':$url['path'])." HTTP/1.1\r\n"); fputs($fp,"Host:$url[host]\r\n\r\n"); while(!feof($fp)) { $tmp = fgets($fp); if(trim($tmp) == '') { break; } elseif(preg_match('/Content-Length:(.*)/si',$tmp,$arr)) { return trim($arr[1]); } } return null; } else { return null; } } 办法四:file_get_contents
$fCont = file_get_contents("http://www.cnmiss.cn/"); echo strlen($fCont)/1024;

以上就是php ie下载文件名乱码怎样办的具体内容,更多请存眷资源魔其它相干文章!

标签: php php教程 php故障解决 php使用问题

抱歉,评论功能暂时关闭!