On Thu, October 12, 2006 11:43 am, Peter Lauri wrote:
> I have a problem. I am using readfile() to send files to the browser.

> I have three different files that I am sending. They are 3MB, 15MB and
> 59MB

> Is there any limitations or settings of how large the files can be
> when
> using readfile()? If so, are they settable?

readfile() will slurp the whole file into RAM, and then spit it out to
the browser.

It's super-convenient and easy for small files.

It's not a Good Idea for large files.

fopen/fread/echo loop is your buddy.

I'll bet a dollar that your old setting had a different memory_limit
in php.ini  -- or none at all, or it wasn't even compiled to allow
memory_limit -- something along those lines.

Actually, depending on the speed of the server, and its hard drives,
and the drive caches, etc, it's entirely possible that the server is
just taking TOO LONG to spit out that monster file.  wget would
probably let you find out pretty quickly if it's RAM or speed that's
killing you.  But it's kinda moot, really, as the solution either way
remains the same.

> header("Pragma: public");
> header("Expires: 0"); // set expiration time
> header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
> header("Content-Type: application/octet-stream");
> header("Content-Disposition: attachment; filename=$Row[filename]");
> header("Content-Transfer-Encoding: binary");

You got Content-type: right, but you know that filename thing is only
going to work on some browsers, right?
http://richardlynch.blogspot.com

Actually, I think -Type should be -type and it might be
case-sensitive, but I'd have to re-read HTTP specs to be 100% sure,
and I think all the browsers ignore case anyway, so it's kind of moot,
and I'm not THAT bored...


//readfile($filelocation);
$file = fopen($filelocation);
while (!feof($file)){
  //Last I heard, 2048 optimized some PHP internal buffer...
  //That's probably way out of date!
  //And does not account for your bandwidth bottle-neck anyway.
  //Play with the 2048 until you're happy.
  echo fread($file, 2048);
}

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

Reply via email to