Hi,

I am getting some problem to open the pdf file which is downloaded via PHP header.After download when I try to open this Its give me the error like

"Adobe could not open this file either its not supported or file has been demaged it was sent as an email attachment and was not correctly decoded"

Can any body help me.

The code I am using that is:

<?php  
include "connection.php"; $tableName=" tbl_time_table,tblclass,tbladditionalinfo "; $fields="tb_code,c_desc,date_format(tb_date,'%d-%m-%Y') as myDate,class_code_fk,note,ad_userlogin"; $filter="class_code_fk='$classes' and class_code_fk=c_id and tb_date='$date' and ad_id='$user_id' and prepared_by_employee_code='$user_id'"; $gotten =$dbObject->select_Records_Feilds_Filter($tableName, $fields, $filter); $row = mysql_fetch_array($gotten); $bytes = $row['c_desc']; header("Content-type: application/pdf"); header('Content-disposition: attachment; filename="thing.pdf"'); readfile('thing.pdf'); ?>

    Try this:

    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename="FILENAME"');
    header('Content-Transfer-Encoding: binary');
    header('Expires: 0');
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    header('Pragma: public');
    header('Content-Length: ' . filesize("PATH/TO/FILE"));
    ob_clean();
    flush();
    readfile(PATH/TO/FILE); 	
    exit();
    

    And obviously replace "FILENAME" and both "PATH/TO/FILE" instances with your actual info.

      Thanks for the Help now its working!!!!!!!!!!!!!!!!!

        7 years later
        anakadote;10950768 wrote:

        Try this:

        header('Content-Description: File Transfer');
        header('Content-Type: application/octet-stream');
        header('Content-Disposition: attachment; filename="FILENAME"');
        header('Content-Transfer-Encoding: binary');
        header('Expires: 0');
        header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
        header('Pragma: public');
        header('Content-Length: ' . filesize("PATH/TO/FILE"));
        ob_clean();
        flush();
        readfile(PATH/TO/FILE); 	
        exit();
        

        And obviously replace "FILENAME" and both "PATH/TO/FILE" instances with your actual info.

        thanks you so much it is working!!!!

          Write a Reply...