PDF下载是否用单引号引起来? [英] PDF downloads surrounded by single quotes?

查看:105
本文介绍了PDF下载是否用单引号引起来?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如您可能从标题中获得的那样,我在Mozilla或Internet Explorer中设置PDF下载时遇到问题.如果出于任何原因尝试下载something.pdf,它都会变成'something.pdf',外面带有单引号,这当然使它无法读取,因为它不是有效的文件扩展名.我一直在寻找遇到同样问题的人,很少遇到实例,这些实例都没有适合我的解决方案.我很迷路,一直试图弄清楚这一点,所以我在这里.以下是下载发生的代码部分. PHP变量$ OrderNumber只是一个五位数字,而$ FileNameToDownload是指向PDF位置的完整目录(我已检查该目录以确认没有单引号).

I am having a problem with setting up PDF download in Mozilla or Internet Explorer, as you probably got from the title. If I attempt to download something.pdf for whatever reason it becomes 'something.pdf' with the single quotes on the outside, and this of course makes it impossible to read because it is not a valid file extension. I have been looking for people experiencing the same problem, and came across very few instances, none of which had solutions that worked for me. I am pretty lost and have been trying to figure this one out for a while, and so here I am. Following is the part of the code where the download occurs. The PHP variable $OrderNumber is simply a five digit number, and $FileNameToDownload is an entire directory pointing to the location of the PDF (which I have checked to verify that is does not have single quotes).

header('Content-Description: File Transfer');
header('Content-Type: application/zip');
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: application/download");
header("Content-Disposition: attachment;filename='$OrderNumber'");
header("Content-Transfer-Encoding: binary ");
header('Content-Length: ' . filesize($FileNameToDownload));
while(ob_get_level()) ob_end_clean();
flush();
readfile($FileNameToDownload);

唯一存在问题的浏览器是Mozilla和IE.在Chrome和Opera中,它似乎可以正常工作.任何帮助都将不胜感激,因为我已经被卡住了一段时间而没有前进.如果有另一种下载PDF的方式,我对此非常开放,但是我发现并尝试过的所有其他方法在控制台中都给我带来了安全错误,因为它试图从中提取PDF.非常感谢,如果需要更多详细信息,我很乐意提供,但是我尽力做到了透彻.

The only browsers that there is an issue in is Mozilla and IE. In Chrome and Opera it seems to work perfectly fine. Any help at all would be appreciated, as I've been stuck for a while without moving forward. If there is an alternate way of downloading PDFs I am very open to it, but all methods I found and tried besides this one gave me security errors in the console because of where it was trying to pull the PDF from. Thank you very much, and if any more detail is needed I would be happy to provide it, but I tried to be as thorough as I could.

推荐答案

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

如果您不想在文件名中加上引号,请不要在文件名中加上引号.

Don't put quotes in the filename if you don't want quotes in the file name.

Firefox只是按照您的指示去做,而不是假设您犯了一个错误.

Firefox is just doing what you are telling it to do instead of assuming you made an error.

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


在旁边:


Aside:

    header('Content-Type: application/zip');
    header("Content-Type: application/force-download");
    header("Content-Type: application/download");

文档只能具有一个内容类型".你为什么要设定三个?

A document can only have one Content-Type. Why are you trying to set three?

它们都不是正确的.您说您正在提供PDF:

None of them are correct anyway. You said you were serving a PDF:

header('Content-Type: application/pdf');

这篇关于PDF下载是否用单引号引起来?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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