Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Im trying to get a website to have a button that forces a download of a pdf.

Heres the html of the button:

    <a href=scripts/download.php>
    <input type="image" src="images/download.gif" alt="Submit button"/>
    </a>

And the php script so far:

    <?php
    header('Content-Type: application/pdf');
    header('Content-disposition: attachment;filename=documents/ECM_IT_ResumeDownload.pdf');
    readfile('documents/ECM_IT_ResumeDownload.pdf');
    ?>

This seems to download the file fine but when I go to open it i get this error:

"Adobe Reader could not open 'documents_ECM_IT_ResumeDownload.pdf' because it is either not a supported file type or because the file has been damaged (for example, it was sent as an email attachment and wasn't correctly decoded)."

Any help would be greatly appreciated.

EDIT Opened the pdf in a text editor and got this message:

"
Warning: readfile(documents/ECM_IT_ResumeDownload.pdf) [function.readfile]: failed to open stream: No such file or directory in html/scripts/download.php on line 4
"

The document is definitely there though. in html/documents/ECM_IT_ResumeDownload.pdf

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
451 views
Welcome To Ask or Share your Answers For Others

1 Answer

$file_url = www.example.com/pdffolder/$pdfname;
header('Content-Type: application/pdf');
header("Content-Transfer-Encoding: Binary");
header("Content-disposition: attachment; filename=".$pdfname);
readfile($file_url);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...