Re: [PHP] Download adds ^M to beginning of file
On Tue, December 12, 2006 9:12 am, [EMAIL PROTECTED] wrote: Based on your subject line, I'd suggest looking for an included PHP script that has a stray newline (a Windows newline, actually) before the ?php or after the ? 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.. If you are using Perl, why are you posting it here?... 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); I know I've posted this twice today, but here we are again: http://richardlynch.blogspot.com/ $file = fopen($completePath, 'r'); while(ob_get_level()) { ob_end_flush(); } while(!feof($file)) { echo fread($file, 2048); } fclose($file); Where can I start? Could it be server config? Or could it have to do with flush? If I remove the ob_end_flush() it does not crash Firefox. Why do you have the ob_end_flush() in there anyway? Is this code on your server that you control? Then you shouldn't have any ob_start() calls in your way in the first place. :-) -- Some people have a gift link here. Know what I want? I want you to buy a CD from some starving artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Download adds ^M to beginning of file
On Tue, December 12, 2006 9:27 am, Jochem Maas wrote: 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); Oh yeah. Where did $size come from? I see it nowhere... $file = fopen($completePath, 'r'); // no need to fopen/fclose if you decide to use readfile()... readfile is great for small files. Not so much for monster downloads, where the browser times out while PHP tries to suck the whole file into RAM, in *some* versions of PHP. -- Some people have a gift link here. Know what I want? I want you to buy a CD from some starving artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Download adds ^M to beginning of file
[EMAIL PROTECTED] 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