douju5062 2015-01-12 10:22
浏览 60

无法使用readfile下载文件

I try to offer a pdf-file-download, handeled in dwhandler.php. All this is supposed to do is open the pdf-file or start a download of it. I tried:

<?php
header("Content-Description: File Transfer");
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename='Paper.pdf'");
header("Cache-Control: must-revalidate");
readfile("Paper.pdf");
exit;
?>    

I also tried some other headers, but none worked.

The browser keeps opening the file directly in some weird coding. Here is a pic of the first few lines: http://www.directupload.net/file/d/3865/h8waniq9_jpg.htm

Has anybody an idea why this is happening? I have no idea what is left to try...

Thank you very much!

  • 写回答

2条回答 默认 最新

  • douyouqian8550 2015-01-12 10:27
    关注

    is html not a option? I know you can offer files to download with simply using html 5 by doing

    <a href="example.pdf" download>download not open it</a>
    

    Take a look into: Forcing to download a file using PHP

    评论

报告相同问题?