XiaoRulez Posted May 29, 2007 Share Posted May 29, 2007 Heres what i got: session_start(); function send_file($path, $name) { ini_set("max_execution_time", "".(60*60*24)); // 24 hours header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Length: '.filesize($path)); header('Content-Disposition: attachment; filename="'.$name.'"'); header("Pragma: no-cache"); header("Expires: 0"); $fp = fopen($path, 'rb'); while(!feof($fp)) { if(connection_aborted()) die(); echo fread($fp, 1024); flush(); } fclose($fp); } if (@$_SESSION['fid'] == base64_encode(session_id())) send_file(base64_decode($_SESSION['file']),base64_decode($_SESSION['fname'])); Now, heres my problem; Everything works fine exept rar files, i tryed: rar, zip, txt, asm a 302 byte rar file only sends 287 bytes :S i checked the filelength, which was 302 in the header. maybe something in in the rar's end of file? oh, and 1 more funny thing, if i remove the content-length header, it works. but i need it... output for die('Content-Length: '.filesize($path)); was Content-Length: 302 Apache 1.3.X, PHP 5.1 Quote Link to comment https://forums.phpfreaks.com/topic/53348-file-streaming-problem/ Share on other sites More sharing options...
XiaoRulez Posted May 30, 2007 Author Share Posted May 30, 2007 okok, i got news... lol, it works under FlashGet (a download manager), but not firefox or ie or even opera 8... in IE it displays as 287 bytes after download, but in opera, it displays as the correct 302b, however, only 302 is downloaded... :S i really need this done, i'm expecting this script to go live in a week or 2 Y_Y Quote Link to comment https://forums.phpfreaks.com/topic/53348-file-streaming-problem/#findComment-264367 Share on other sites More sharing options...
MadTechie Posted May 30, 2007 Share Posted May 30, 2007 try adding header("Content-Transfer-Encoding: binary"); Quote Link to comment https://forums.phpfreaks.com/topic/53348-file-streaming-problem/#findComment-264372 Share on other sites More sharing options...
XiaoRulez Posted May 30, 2007 Author Share Posted May 30, 2007 :S nope, "header("Content-Transfer-Encoding: binary");" dosn't fix it. it always has problems at the last % or so... wither the files are large or small... maybe the connection is cut just before it finish's... need my phpinfo for a better idea? Quote Link to comment https://forums.phpfreaks.com/topic/53348-file-streaming-problem/#findComment-264382 Share on other sites More sharing options...
MadTechie Posted May 30, 2007 Share Posted May 30, 2007 try change $fp = fopen($path, 'rb'); while(!feof($fp)) { if(connection_aborted()) die(); echo fread($fp, 1024); flush(); } fclose($fp); to readfile($path); when the file downloads.. open it in wordpad and check the top to see if theirs any php output (ie errors) Quote Link to comment https://forums.phpfreaks.com/topic/53348-file-streaming-problem/#findComment-264386 Share on other sites More sharing options...
XiaoRulez Posted May 30, 2007 Author Share Posted May 30, 2007 :S i don't want to use readfile, because as some of the files are WAY over 100mb, i really don't wanna blow my memory by loading 100 megs into it with readfile :S Quote Link to comment https://forums.phpfreaks.com/topic/53348-file-streaming-problem/#findComment-264388 Share on other sites More sharing options...
XiaoRulez Posted May 30, 2007 Author Share Posted May 30, 2007 i did this: $s=fread($fp, $block_size); echo(''.strlen($s)); 302...lol but when i have echo($s); only echos 287 characters... maybe archives have special characters :S, cos it works with practically every other file type... damages rar, zip, even uha :S couldn't try ace... can't afford it rmvb's, and avi's seem perfect. i was also wondering if there was a way for the script to load like a buffer? cos it's just sending the whole file as fast as it can (ie. HDD goes crazy for about a few seconds, then stops...lol) Quote Link to comment https://forums.phpfreaks.com/topic/53348-file-streaming-problem/#findComment-265055 Share on other sites More sharing options...
MadTechie Posted May 30, 2007 Share Posted May 30, 2007 with zip files i had a ton of problems, (i created the zip on the fly) i used this and it works perfectly <?php $archiveName = "whatever.zip"; if(ini_get('zlib.output_compression')) { ini_set('zlib.output_compression', 'Off'); header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: private",false); header("Content-Type: application/zip"); header("Content-Disposition: attachment; filename=".basename($archiveName).";" ); header("Content-Transfer-Encoding: binary"); header("Content-Length: ".filesize($archiveName)); readfile("$archiveName"); exit; ?> as for readfile vs fread i have had less problems with readfile (try decreaseing the block size on fread, see how that affects it) Quote Link to comment https://forums.phpfreaks.com/topic/53348-file-streaming-problem/#findComment-265160 Share on other sites More sharing options...
XiaoRulez Posted May 30, 2007 Author Share Posted May 30, 2007 well, for the time being, I'm taking out the content length, it seems to fix it up a bit. what would happen if i set the content just a kb over the actual? will people die? Quote Link to comment https://forums.phpfreaks.com/topic/53348-file-streaming-problem/#findComment-265228 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.