Script to manage downloads - strange problem.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
MonkeyWorks
Forum Newbie
Posts: 2
Joined: Mon May 29, 2006 1:36 pm

Script to manage downloads - strange problem.

Post by MonkeyWorks »

Helo everybody, I'm Eduardo from Bs.As., Argentina, I'm working on a sound technology web site project and this is my first post on DevNetowrk Forums :)

I came here because I have a problem I can't seem to resolve alone, and it is giving me a real headache.

I wrote a script to manage downloads on my site, based on some other stuff I found with google, on forums, php.net, etc. I also readed some posts here (very useful) but they didn't help at all to solve my problem.
The script will just control that the user is logged in, if he is, it will let him download a file. This works perfectly, with no errors. The user can start a download and finish it with no problems, but THE PROBLEM comes here:

If the user is downloading two files at the same time, the browser wont let him go to other web pages on my site, not even will permit him refresing the downloads page until one of the two downloads is finished.

I tested this on FIREFOX (last version and olders), Internet Explorer (SP2 and SP1), and also in Opera.

This problem does not occur while using Opera to download files with my download.php script.

I have done a lot to search the problem, today I have also wrote an extremly simplified version of the script (wich I will post here) but the same problem occurs.

Maybe some more experienced people have had this problem and can guide me to solve it.

I Would appreciate any help.

HERE IS THE CODE OF THE SIMPLIFIED VERSION:



// The Original script has session_start(); and session_write_close() (before header();)

Code: Select all

$fname = $_GET['file'];
$fpath = $_SERVER['DOCUMENT_ROOT']."/media_all/audiomedia/".$_GET['file'];
$fsize = filesize($fpath);
$bufsize = 20000;

//   header("HTTP/1.1 200 OK");
//   header("Content-Length: $fsize");
//   header("Content-Type: application/force-download");
   header("Content-Disposition: attachment; filename=$fname");
//   header("Content-Transfer-Encoding: binary");
//   header("Cache-Control: private");

   if(file_exists($fpath) && $fh = fopen($fpath, "rb")){
       while($buf = fread($fh, $bufsize))
           print $buf;
       fclose($fh);

   } else {

       header("HTTP/1.1 404 Not Found");
   }
(This code will let a user download a file, but if two files are downloaded at the same time, he wont be able to refresh the page or go to other pages inside my web site)

Again, thanks for your help.

Eduardo.
MonkeyWorks
Forum Newbie
Posts: 2
Joined: Mon May 29, 2006 1:36 pm

Post by MonkeyWorks »

Any idea?

Thanks
Post Reply