Question:

How does a php returns a pdf file or an exe file?

by  |  earlier

0 LIKES UnLike

hi

Can you tell me how does a php returns an executable file or a php file or... for downloading without resume support?

 Tags:

   Report

1 ANSWERS


  1. Two steps:

    1) send appropriate header

    2) send the file

    The appropriate headers could be sent as follows:

    header( "Content-type: application/octet-stream" );

    header( "Content-disposition: attachment; filename=$suggest_a_file_name" );

    The first line states that the following data should be interpreted as a binary file. Second line stated that the data should be treated as an attachment. You should suggest a file name otherwise browsers will display the php script's name in the "save as" dialog -- so a pdf file might get saved as download.php.

    The file data then could be sent as follows:

    echo file_get_contents( "files/file.pdf" );

    You can also use fopen, fread and fclose for this part. DONOT echo anything else or file will be corrupted.

Question Stats

Latest activity: earlier.
This question has 1 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.