Author Topic: problem downloading big files  (Read 21830 times)

0 Members and 1 Guest are viewing this topic.

Offline k4nth

  • Newbie
  • *
  • Posts: 28
    • View Profile
problem downloading big files
« on: March 14, 2003, 07:04:14 PM »
Hi, i can't seem to download big files (500MB) using the download button.  It takes ages to respond and when it finally tries to download the file, only around 650KB is being downloaded. How can i fix this problem?

Offline Chris

  • 4images Moderator
  • 4images Guru
  • *****
  • Posts: 4.487
  • Did u ever stop to think and then forget to start?
    • View Profile
problem downloading big files
« Reply #1 on: March 14, 2003, 07:07:12 PM »
Open download.php and locate this code:
Code: [Select]
 if (!empty($file['file_path'])) {
    @set_time_limit(120);
    if ($remote_url) {
      header("Location: ".$file['file_path']);
      exit;
    }

Try increasing 120 to 300 or some higher number.  This page documents what the set_time_limit function does:

http://www.php.net/manual/en/function.set-time-limit.php

Offline k4nth

  • Newbie
  • *
  • Posts: 28
    • View Profile
problem downloading big files
« Reply #2 on: March 14, 2003, 07:19:18 PM »
tried that, still the same problem. any other suggestions? When i opened the downloaded wmv file using notepad, i found this error message.

HTTP/1.1 400 Bad Request Date: Fri, 14 Mar 2003 18:29:45 GMT Server: Apache/1.3.27 (Unix) mod_log_bytes/1.0 mod_bwlimited/1.0 PHP/4.3.1 FrontPage/5.0.2.2510 mod_ssl/2.8.12 OpenSSL/0.9.6b Connection: close Content-Type: text/html; charset=iso-8859-1
Bad Request
Your browser sent a request that this server could not understand.
The request line contained invalid characters following the protocol string.




--------------------------------------------------------------------------------

Apache/1.3.27 Server at localhost.localdomain Port 80

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
problem downloading big files
« Reply #3 on: March 14, 2003, 09:37:29 PM »
that's probably because 4images checking if the file exist on the server, that makes PHP load it into memory (atleast that what I have on my windows+apache server), and if in php.ini set memory limit per script is too little (2mb by default) it could cause the error.
I probably wrong, but thats my theory ;)
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline Chantique

  • Pre-Newbie
  • Posts: 9
    • View Profile
problem downloading big files
« Reply #4 on: May 07, 2003, 12:10:43 AM »
about movies...

do we have to use broadband to watch the movies ? i mean the connections.. cause it seems my friends who is using modem can't watch my movies and they said it keeps buffering all the time  :roll:  :(

Offline Robinini

  • Pre-Newbie
  • Posts: 5
    • View Profile
Re: problem downloading big files
« Reply #5 on: June 05, 2007, 12:19:45 PM »
I had a similar problem with files of about 6Mb. I investigated the PHP file read limit size and indeed, the download function makes use of a function which has a read limit problem for some servers. I located the download code and replaced it with a function which reads the file in chunks, eliminating the readfile limit problem.

It took ages to work out and it seems to have worked for me, and I would be interested to hear if it works for others too....

In file download.php;
Before "function get_remote_file($url) {" which is approximately line 33, insert;

function readfile_chunked($filename,$retbytes=true) {
   $chunksize = 1*(1024*1024); // how many bytes per chunk
   $buffer = '';
   $cnt =0;
   $handle = fopen($filename, 'rb');
   if ($handle === false) {
       return false;
   }
   while (!feof($handle)) {
       $buffer = fread($handle, $chunksize);
      // echo $buffer;
      ob_flush();
      flush();
       if ($retbytes) {
           $cnt += strlen($buffer);
       }
   }
       $status = fclose($handle);
   if ($retbytes && $status) {
       return $cnt; // return num. bytes delivered like readfile() does.
   }
   return $status;

}


also, to refer to the alternative function, within function get_file_data($file_path) {, replace;

@readfile($file_path);


with

@readfile_chunked($file_path) ;

The readfile_chunked() function is not originally of my own hand, but extracted from http://ch2.php.net/manual/en/function.readfile.php#54295

Offline Robinini

  • Pre-Newbie
  • Posts: 5
    • View Profile
Re: problem downloading big files
« Reply #6 on: June 06, 2007, 07:05:03 AM »
Hello Ivan

I also have the same version of 4images and I have checked the code. It is exactly the same as described above and it works for me. I have no other modifications to the software.

Sorry that it does not work for you at the moment! Note that there will now be a delay before the zip file download commences. Is this what is happening with you? I'm surprised that you have a white screen.

If you like, attach a copy of your download.php and I will check the code when I next get a chance.

Robin

Offline Robinini

  • Pre-Newbie
  • Posts: 5
    • View Profile
Re: problem downloading big files
« Reply #7 on: June 06, 2007, 09:05:14 AM »
Ivan

Attached is my download.php, but saved as .txt in case there is a problem with .php

Please note that "Robin added function2" did not work and is commented out with /* and */ so is not part of the PHP programme. I do not think that I have made any other changes to any other files. If you would like to see anything else, then ask!

Robin

 

Offline Robinini

  • Pre-Newbie
  • Posts: 5
    • View Profile
Re: problem downloading big files
« Reply #8 on: June 07, 2007, 07:17:26 AM »
Ivan, I have tried my site with PHP Version 4.4.4 and PHP 5.1.1.

 PHP Version 4.4.4. - new download.php - Is a problem - as you have said - "Warning: Cannot modify header information - headers already sent by (output started at d:\www\www11..."

 PHP Version 5.1.1 - new download.php - Works - no problem.

This makes me think - is it only the change to PHP 5 which has made it work? I have therefore tried the combination - original 4images download.php and PHP 5.1.1.....

...and there is no problem with large files!! The lesson here is that changing to PHP 5.1.1 solves the problem!!!

Is this possible for you to do!? I would be interested to see if the large 160MB file works also.....

Robin
(It looks like I was wasting our time with the new function, but I learned a lot!)