streaming pdf getting corrupted

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
yacahuma
Forum Regular
Posts: 870
Joined: Sun Jul 01, 2007 7:11 am

streaming pdf getting corrupted

Post 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
User avatar
yacahuma
Forum Regular
Posts: 870
Joined: Sun Jul 01, 2007 7:11 am

Re: streaming pdf getting corrupted

Post 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();
Post Reply