php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48517 forcing download +2mb
Submitted: 2009-06-10 12:18 UTC Modified: 2009-06-10 12:43 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: filmixt at gmail dot com Assigned:
Status: Not a bug Package: Reproducible crash
PHP Version: 5.2.9 OS: Centos
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: filmixt at gmail dot com
New email:
PHP Version: OS:

 

 [2009-06-10 12:18 UTC] 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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-06-10 12:43 UTC] jani@php.net
This place is for reporting bugs in PHP, not for asking questions how to 
use it.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat May 03 15:01:28 2025 UTC