Page 1 of 1

streaming pdf getting corrupted

Posted: Sat Sep 13, 2008 10:50 pm
by yacahuma
Hello,
I am using this function(found at php.net) to stream a pdf from my server. It work perfect on my developing machine(apache on windows xp) but when I move it to the server I an getting corrupted pdf. I dont know where to look since there are no php errors.

The function is

Code: Select all

 
session_cache_limiter('none'); //*Use before session_start() 
set_time_limit(0);
function DownloadFile($file,$filename) { // $file = include path 
        if(file_exists($file)) {
            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($file));
            ob_clean();
            flush();
            readfile($file);
            exit;
        }
 
    }
 
So what can cause a corruped pdf? BTW, the file is NOT corrupted on the server. I ftp the file to my machine and the file is fine. Also remember that it does work on my windows machine.

Thank you

Re: streaming pdf getting corrupted

Posted: Sun Sep 14, 2008 7:30 am
by yacahuma
Is amazing what a good night sleep will do.

It occured to my to just open the file I was getting. And there it was

Code: Select all

 
<br />
<b>Notice</b>:  ob_clean() [<a href='ref.outcontrol'>ref.outcontrol</a>]: failed to delete buffer. No buffer to delete. in <b>/..../htdocs/west/viewfile.php</b> on line <b>14</b><br />
 
 
So I just added @ before every call
@ob_clean();
@flush();
@readfile();