0

这已经发布,但我已经尝试了很多在 SO 上找到的解决方案等等(比如:http ://davidwalsh.name/php-force-download )

我基本上有这个:

{       
    $filePath = '../public/myfile.png';
    $fileName = basename($filePath);
    $fileSize = filesize($filePath);


    if (!is_file) {
        die("File not found");
    } else {                        
        header("Content-Description: File Transfer");
        header('Content-Type: application/octet-stream');
        header("Content-Disposition: attachment; filename= " . $fileName);
        header("Content-Transfer-Encoding: binary");
        readfile($filePath);
    }
}

文件被识别并下载,但 .PNG 为空且 .DOC 已损坏(Word 要求我修复文件,然后就可以了)。我也试过PDF,没问题。

我确实可以放置各种选项(Pragma,Cache-Control,Expires,Content-Length 等),仍然下载文件但以某种方式损坏......

你有没有遇到过我的问题?请考虑我在 IIS 7.5 上

提前致谢

4

1 回答 1

8

使用像Notepad++这样的纯文本编辑器打开下载的文件。在顶部你会发现一个 PHP 错误通知,它会告诉你出了什么问题。

错误可能是“会话已发送”。然后ob_start();在脚本的开头添加。

于 2012-06-11T13:12:25.667 回答