【问题标题】:Cannot download pdf using ipad无法使用 ipad 下载 pdf
【发布时间】:2013-10-22 18:43:13
【问题描述】:

我正在使用以下功能下载 pdf 文件,当我从 PC 或笔记本电脑下载它时它工作正常,但是当我使用 ipad 单击下载链接时,它会打开一个包含许多特殊字符的页面,我无法下载文件。

我的下载功能是

public function download() {
    $download_path = $_SERVER['DOCUMENT_ROOT'] . "/import";
$filename = $_GET['file'];
    $file = str_replace("..", "", $filename);
    $file = "$download_path/$file";
if (!file_exists($file))
        die("Sorry, the file doesn't seem to exist.");
    $type = filetype($file);
    header("Content-type: $type");
    header("Content-Disposition: attachment;filename=$filename");
    header('Pragma: no-cache');
    header('Expires: 0');
    readfile($file);
}

关于这个错误的任何想法?

【问题讨论】:

  • 确保字符集匹配
  • 字符集应该是什么?我正在使用 utf-8
  • 确保您的 iPad 也看到了这些内容。
  • 如何确定?
  • 这似乎很不安全......

标签: php ipad codeigniter


【解决方案1】:

这可能是问题:

$type = filetype($file);
header("Content-type: $type");

来自manual

可能的值是 fifo、char、dir、block、link、file、socket 和 未知。

哪些不是您希望在标题中看到的内容。您可能正在寻找:

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

【讨论】:

  • 我应该将 content-type 替换为您建议的吗?
【解决方案2】:

您可能想要 finfo_file() 而不是 filetype()

【讨论】:

    猜你喜欢
    • 2017-09-21
    • 2018-04-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多