Re: Download adds ^M to beginning of file

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



lists@xxxxxxxxxxx wrote:
> Hi,



> 
> Using the below code to force download works fine on most servers and
> with most
> browsers. However it does "crash" Firefox when I download a specific
> file, IE
> works like beauty. File content starts with:
> 
> #!/sbin/_joor_perl_use Filter::decrypt......
> 
> This is the code to force the download:
> 
> header("Pragma: public");
> header("Expires: 0");
> header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
> header("Content-Type: application/octet-stream");
> header("Content-Disposition: attachment; filename=\"$file\"");
> header("Content-Transfer-Encoding: binary");
> header("Content-Length: $size");
> $file = fopen($completePath, 'r');

// no need to fopen/fclose if you decide to use readfile()...

> 
> while(ob_get_level()) {
>     ob_end_flush();
> }

// this should be:
while(ob_get_level()) ob_end_clean(); // discard all output!

> 
> while(!feof($file)) {
>     echo fread($file, 2048);
> }
> 
> fclose($file);

// and this could probably be better written as:
@readfile($file); // read the whole file directly to the output buffer

> 
> Where can I start? Could it be server config? Or could it have to do
> with flush?

at a guess: yes.

> If I remove the ob_end_flush() it does not crash Firefox.
> 
> Best regards,
> Peter Lauri
> 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux