日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > php >内容正文

php

php ie 下载 乱码,php ie下载文件名乱码怎么办

發布時間:2024/7/23 php 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 php ie 下载 乱码,php ie下载文件名乱码怎么办 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

php ie下載文件名亂碼的解決辦法:1、通過header方法解決亂碼;2、通過“function remote_filesize($uri,$user='',$pw='') {...}”等方法解決亂碼。

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直接獲取大小了。

方法二:curlfunction 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 '
head-->'.$head.''; // 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 ie下载文件名乱码怎么办的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。