有很多朋友下载文件时都是把中文名转换在英文或全数字的然后再进行下载,下面我来介绍直接利用中文文件名文件下载并且不出现乱码的解决办法,代码如下:
- <?php
- $filename = "中文 文件名.txt";
- header('Content-Type: application/octet-stream');
- header('Content-Disposition: attachment; filename=' . $filename);
- print "Hello!";
- ?>
把程序保存成UTF-8编码再访问,IE6下载的文件名就会乱码,FF3下下载的文件名就只有“中文”两个字,Opera 9下一切正常,输出的header实际上是这样子:
Content-Disposition: attachment; filename=中文 文件名.txt
其实按照RFC2231的定义,多语言编码的Content-Disposition,应该这么定义:
Content-Disposition: attachment; filename*="utf8''%E4%B8%AD%E6%96%87%20%E6%96%87%E4%BB%B6%E5%90%8D.txt"
即:filename后面的等号之前要加 * ,filename的值用单引号分成三段,分别是字符集(utf8)、语言(空)和urlencode过的文件名,最好加上双引号,否则文件名中空格后面的部分在Firefox中显示不出来.
注意:urlencode的结果与php的urlencode函数结果不太相同,php的urlencode会把空格替换成+,而这里需要替换成%20
实例代码如下:
- <?php
- $file = "/tmp/中文名.tar.gz";
- $filename = basename($file);
- header("Content-type: application/octet-stream");
- //处理中文文件名
- $ua = $_SERVER["HTTP_USER_AGENT"];
- $encoded_filename = urlencode($filename);
- $encoded_filename = str_replace("+", "%20", $encoded_filename);
- if (preg_match("/MSIE/", $ua)) {
- header('Content-Disposition: attachment; filename="' . $encoded_filename . '"');
- } else if (preg_match("/Firefox/", $ua)) {
- header("Content-Disposition: attachment; filename*="utf8''" . $filename . '"');
- } else {
- header('Content-Disposition: attachment; filename="' . $filename . '"');
- }
- header('Content-Disposition: attachment; filename="' . $filename . '"');
- header("Content-Length: ". filesize($file));
- readfile($file);
- ?>
这样我们就完全解决了中文文名乱码这个问题了。
波比源码 – 精品源码模版分享 | www.bobi11.com
1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长!
2. 分享目的仅供大家学习和交流,您必须在下载后24小时内删除!
3. 不得使用于非法商业用途,不得违反国家法律。否则后果自负!
4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
5. 如有链接无法下载、失效或广告,请联系管理员处理!
6. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需!
7. 本站源码并不保证全部能正常使用,仅供有技术基础的人学习研究,请谨慎下载
8. 如遇到加密压缩包,请使用WINRAR解压,如遇到无法解压的请联系管理员!
波比源码 » php实现中文文件名文件下载
波比源码 » php实现中文文件名文件下载
purchase levaquin pill order levofloxacin 500mg pill
order avodart without prescription buy avodart generic buy ondansetron 8mg online
order aldactone fluconazole sale fluconazole brand
cheap ampicillin 250mg brand erythromycin 250mg erythromycin brand
order fildena 100mg purchase methocarbamol online robaxin order online
lamotrigine 200mg without prescription order vermox 100mg sale tretinoin gel canada
tadalis 10mg uk diclofenac 50mg generic purchase voltaren for sale
cheap cialis online online ed drugs cheap viagra tablets
vrai cialis 10mg prix tadalafil 10mg prix viagra 100mg pas cher
cialis 20mg bestellen cialis 20mg generika viagra kaufen ohne rezept
order accutane 10mg sale azithromycin order buy oral ivermectin
buy modafinil Cialis buy online acetazolamide uk
ramipril us order irbesartan 150mg for sale brand azelastine
order buspirone 10mg online cheap ditropan 5mg pill oxybutynin 2.5mg pill
hytrin 1mg uk terazosin online sulfasalazine 500mg price
brand benicar 10mg cheap diamox 250 mg diamox 250 mg price
order isosorbide sale digoxin 2250 mg cheap order micardis 20mg pill
bupropion 150mg usa buy strattera 25mg quetiapine without prescription
buy zoloft 100mg pill purchase zoloft for sale cheapest viagra
order imuran 100 mcg protonix ca order sildenafil sale
buy tadalafil pill generic cialis order amantadine generic
avlosulfon online aceon canada buy perindopril for sale
buy modafinil 200mg pill cheap online pharmacy ivermectin 3mg stromectol
order luvox 50mg online cheap order ketoconazole 200mg pills glucotrol ca
isotretinoin 40mg canada oral amoxicillin 250mg deltasone price
cialis 10mg tablet purchase cialis online cheap anafranil 25mg brand
glycomet 500mg uk order atorvastatin 80mg sale cialis overnight delivery
order olanzapine pills order generic olanzapine 10mg diovan oral
order norvasc 10mg for sale order sildenafil 100mg order tadalafil 40mg generic
viagra pill brand sildenafil 50mg purchase lisinopril online cheap
writing a paper real money slot machines online casino slots
clomid 100mg without prescription real online casino roulette free play for fun
cialis tadalafil 40mg cialis drug oral viagra 100mg
cheap triamcinolone 4mg triamcinolone 4mg canada buy desloratadine 5mg online cheap
buy dapoxetine pills order dapoxetine pill levothyroxine sale
tadalafil 40mg for sale purchasing viagra on the internet viagra 150mg price
buy xenical buy orlistat 60mg buy acyclovir 400mg online
price cialis plavix 150mg tablet purchase clopidogrel online
zyloprim 100mg pill order rosuvastatin generic ezetimibe buy online
losartan 25mg canada buy cozaar sale topiramate 100mg oral
order zantac online mobic 15mg cost celebrex 200mg tablet
online casino real money paypal roulette wheel online luckyland slots
order cialis pill buy ampicillin 250mg generic order ciprofloxacin 500mg
cost metronidazole 200mg buy clavulanate online buy generic bactrim
diflucan 100mg tablet buy diflucan 200mg generic cheap viagra
buy tadalafil 40mg pill brand tadalafil buy viagra online cheap
blackjack online real money generic cialis india buy cialis 10mg sale
purchase trazodone pills buy generic sildenafil 50mg order sildenafil 50mg pills
order deltasone pills buy deltasone 10mg amoxil 500mg pill
order generic viagra 50mg sildenafil 50mg canada cost tadalafil 40mg
play real poker online sexual dysfunction buy cialis 40mg online
cheap lasix generic plaquenil 400mg cheap hydroxychloroquine 200mg
sildenafil 100mg pills order tamoxifen 10mg online budesonide oral
generic tretinoin cream order tretinoin gel online avana price
buy tadalafil 20mg pill order voltaren pill order indomethacin 50mg online cheap
buy lamisil 250mg for sale lamisil drug buy trimox online
naprosyn 250mg cheap cefdinir 300 mg pill buy lansoprazole pill
cialis 40mg cheap Best price cialis play blackjack online for real money
cialis tadalafil Cialis overnight oral cialis 10mg
gambling online real money casino app black jack card game free
buy altace pill order arcoxia 60mg sale purchase etoricoxib pills
buy doxycycline without prescription buy doxycycline 100mg cleocin 150mg over the counter
mesalamine usa astelin 10 ml tablet generic avapro
purchase temovate without prescription buspar 5mg pills amiodarone online order
order diamox pills brand imdur 20mg buy azathioprine 50mg online
amoxicillin 500mg drug amoxil over the counter stromectol tab price
cost alendronate 35mg alendronate us motrin us
order dapoxetine 30mg sale generic priligy 90mg order motilium 10mg
generic famotidine brand tacrolimus 5mg cost mirtazapine
doxycycline 100mg uk cheap chloroquine 250mg medrol 16 mg online
order nexium capsules buy esomeprazole 40mg furosemide 100mg ca
buy glucophage 500mg sale tamoxifen 20mg over the counter order generic nolvadex
order provigil generic buy promethazine 25mg promethazine 25mg cheap
isotretinoin 10mg ca ampicillin over the counter ampicillin 250mg over the counter
best natural ed pills buy proscar 5mg for sale order propecia 5mg online
buy ivermectin 3 mg for humans buy ed pills cheap order deltasone 10mg pills
purchase zofran pills cheap bactrim 480mg trimethoprim for sale
buy ventolin 2mg generic ventolin 2mg pills order augmentin 375mg online
dutasteride sale avodart pills xenical 120mg tablet
order vibra-tabs generic oral doxycycline 200mg buy generic zovirax
azathioprine 50mg price buy micardis 20mg for sale naprosyn over the counter
ditropan 5mg cheap cheap trileptal buy oxcarbazepine 300mg generic