2012-04-12 52 views
1

我使用以下功能下载pdf文件时,它工作正常,当我从PC或笔记本电脑下载时,但当我点击下载链接使用ipad时,它打开一个页面,有很多特殊的字符和我我无法下载该文件。无法使用ipad下载pdf

我的下载功能是

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); 
} 

关于此错误的任何想法?

+0

确保字符集匹配 – 2012-04-12 12:30:22

+0

字符集应该是什么?我正在使用utf-8 – 2012-04-12 12:32:11

+0

确保这就是您的iPad所看到的。 – 2012-04-12 12:32:29

回答

3

这可能是这个问题:

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

manual

可能的值是FIFO,焦炭,目录,块,链接,文件,插座和 未知。

哪些不是你想要在标题中看到的东西。您可能正在寻找:

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

我应该用你建议的内容替换内容类型吗? – 2012-04-12 12:41:59

+0

对于pdf:是的。 – Nanne 2012-04-12 12:57:16

+0

非常感谢:) – 2012-04-12 13:01:47