Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/53348-file-streaming-problem/
Share on other sites

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

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)

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 :P

 

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)

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)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.