ID: 48517
Updated by: [email protected]
Reported By: filmixt at gmail dot com
-Status: Open
+Status: Bogus
Bug Type: Reproducible crash
Operating System: Centos
PHP Version: 5.2.9
New Comment:
This place is for reporting bugs in PHP, not for asking questions how
to
use it.
Previous Comments:
------------------------------------------------------------------------
[2009-06-10 12:18:12] filmixt at gmail dot com
Description:
------------
Hi everyone,
This is the first time I post here, I hope you could help me with a
hard one.
I'm making a project, where I have to force the download and print the
content of a 700mb-1gb file. Problems? Well, a lot. Why? You'll see..
:D
If we do this:
[code=text]// FILE EXTERNAL[]
$f = $_GET["f"];
// Size
function urlfilesize($url,$thereturn) {
$x = array_change_key_case(get_headers($url, 1),CASE_LOWER);
$x = $x['content-length'];
return $x;
}
// Getting size
$peso = urlfilesize($_GET[f],'');
// Headers
header("Content-Type: application/download");
header("Transfer-Encoding: chunked");
header("Content-Disposition: attachment; filename=\"$f\"\n");
header("Content-Length: ".$peso);
readfile($f);[/code]
Once you get to 2MB, the download stops, why?, php hangs.
I've been 4 days looking for an answer or a fix, and I failed. Imagine
how I am :)
This script is very easy, lets go onto a harder one... not too much:
[code=text]// ARCHIVO
$f = $_GET["f"];
// PESO
function urlfilesize($url,$thereturn) {
$x = array_change_key_case(get_headers($url, 1),CASE_LOWER);
$x = $x['content-length'];
return $x;
}
// Tengo PESO
$peso = urlfilesize($_GET[f],'');
// Headers
$name = explode("/", $f);
$nc = count($name);
$nombre = $name[$nc-1];
header('Content-Description: File Transfer');
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header ("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Disposition: attachment; filename=\"$nombre\"\n");
header("Content-Length: ".$peso);
set_time_limit(0);
function readfile_chunked($filename,$retbytes=true)
{
$chunksize = 1*(1024*1024); // how many bytes per chunk
$buffer = '';
$cnt =0;
// $handle = fopen($filename, 'rb');
$handle = fopen($filename, 'rb');
if ($handle === false)
{
return false;
}
while (!feof($handle))
{
$buffer = fread($handle, $chunksize);
echo $buffer;
if ($retbytes)
{
$cnt += strlen($buffer);
}
}
$status = fclose($handle);
if ($retbytes && $status)
{
return $cnt; // return num. bytes delivered like
readfile() does.
}
return $status;
}
readfile_chunked($f,$peso);[/code]
Buffer? The same, it hangs at 2MB.
:D Now what?
I tried:
[code=text]header("Content-Type: application/download");
header("Transfer-Encoding: chunked");
header("Content-Disposition: attachment; filename=\"$f\"\n");
header("Content-Length: ".$peso);
header("Location: $f");[/code]
Funny? Well.. desperate. It doesnt work, it just redirects ;-)
I tried to install lighttpd module, and it just works with LOCAL files,
haha, not useful...
So, in conclusion, Im f**ked up.
I hope there's a master here to show us the way, or someone with an
idea, because I can't handle more...
Thanks everyone for the time.
Expected result:
----------------
Download the file completelly.
Actual result:
--------------
It hangs at 2mb
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=48517&edit=1