在使用文件名空格下载时,Firefox有问题 [英] Firefox has problems when downloading with a space in filename

查看:223
本文介绍了在使用文件名空格下载时,Firefox有问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  header('Content-Type :text / csv'); 
header('Content-Disposition:attachment; filename ='。$ filename);
$ fp = fopen('php:// output','w');
fputs($ fp,$ csvdata);
fclose($ fp);

以下是一个名为 Test_ Grad Fair 2_20140129_1312_607.csv



当我尝试使用上面的代码使用FireFox下载文件时,会发生以下情况。 (主要问题是它删除了文件扩展名!)



当我尝试从Safari或Chrome下载时: img src =https://i.stack.imgur.com/tyJVj.pngalt =从Safari下载>



 
 



我知道一个解决方案可能是这样做的:

  $ filename = str_replace('','',$ filename); 

不过,我更喜欢弄清楚为什么FireFox会出现这个问题,看起来有点荒谬文件名没有空格。这可能像一个%20 而不是空间问题吗?

解决方案

文件名参数应该用双引号引起来。

  header('Content-Disposition:attachment; filename =''。$文件名。''); 

请参阅 http: //kb.mozillazine.org/Filenames_with_spaces_are_truncated_upon_download


It seems that firefox has a problem with spaces within the filename for downloading...

header( 'Content-Type: text/csv' );
header( 'Content-Disposition: attachment;filename='.$filename);
$fp = fopen('php://output', 'w');
fputs($fp, $csvdata);
fclose($fp);

Here is an example of a file named: Test_ Grad Fair 2_20140129_1312_607.csv

When I attempt to download the file using the code above with FireFox the following occurs. (the main problem is it removes the file extension!)

And when I try downloading it from Safari, or Chrome:

   

I know a solution would be to maybe do something like:

$filename = str_replace(' ', '', $filename);

However, I prefer to figure out why FireFox is having this problem, it seems kinda ridiculous that you can't have a space in a filename. Could this be like a %20 instead of a space problem?

解决方案

The filename parameter should be enclosed in double quotes.

header( 'Content-Disposition: attachment;filename="'.$filename.'"');

See http://kb.mozillazine.org/Filenames_with_spaces_are_truncated_upon_download

这篇关于在使用文件名空格下载时,Firefox有问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆