Jump to content

Recommended Posts

I've got a file hosting website that has been working great for the 3000 files that have been uploaded by my members.

This morning I discovered that once you click on the download link, the file will download, but you can not go back to the website until your download is complete.

The apache server is not limiting the number of connections per IP (it's set at 50 right now)

 

 

Here is the main part of the code I'm using. Everything works and downloads great.

	header('Content-type: ' . $fileDownloader->mime_get_type($file));
	header("Content-Length: ". filesize($file));
	header('Content-Disposition: attachment; filename="' . $v_name . '"');
	header("Content-Transfer-Encoding: binary\n");
	readfile($file);

 

Being that everything else works great, I;m guessing this is a PHP header problem.

 

Once the download is complete or canceled, the page loads no problem.

Link to comment
https://forums.phpfreaks.com/topic/60991-solved-file-download-header-problem/
Share on other sites

When the user goes to the download page, it displays a button. that button posts to

$_SERVER['PHP_SELF']

then as the page is reloaded, it runs the script that I have posted above.

 

I'mm give running it in another window a shot. It's just a pain to have the new window popup.

i use this (for zips)

 

	header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false);
header("Content-Type: application/zip");
header("Content-Disposition: attachment; filename=".basename($archiveName).";" );
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($archiveName));
readfile("$archiveName");

 

give that a go :)

i don't really think its a header issule. basically readfile is parsing to the current window.. so that session is going to be busy until its finished.. hence another window idea..

 

maybe chucks will work better! (either that or a frameset lol)

 

<?php
function readfile_chunked ($filename) {
  $chunksize = 1*(1024*1024); // how many bytes per chunk
  $buffer = '';
  $handle = fopen($filename, 'rb');
  if ($handle === false) {
    return false;
  }
  while (!feof($handle)) {
    $buffer = fread($handle, $chunksize);
    print $buffer;
  }
  return fclose($handle);
}
?>

Loading a new window doesn't do anything different :(

I'm getting off work in 10 minutes so I'll try the chunks when I get home.

 

Could you post the full code of your download script? I don't see how you would not be able to view the rest of the page while downloading the file.

 

The rest of that page will load, it's that once it loads and the download begins, you can't navigate the website until the download is done, whether complete or canceled.

As for more code, thats the only code on the entire page that has anything to do with the page downloading.

 

Hmm, I may have a new idea!

when i said a new window i mean a script that does the download of the file only, and the current window continues as normal.

 

I'll try messing around with a few ideas to see what I can get to work.

The hardest part is that I need to keep the original file location hidden from the user

i have a database with the paths and ID's i then use download.php?id=1010 and get the 1010 and find the path in the database :)

 

Thats how I do it as well. For some reason no matter what I try, once they start downloading a file, they can't navigate the website. I'm still guessing it's because the header is being used while the whole file downloads. Then once it's complete, the header is free again? Does that make sense or does the header function not work like that?

Here is the header output when the download button is clicked:

 

 

HTTP/1.1 200 OK

Date: Sun, 22 Jul 2007 19:20:32 GMT

Server: Apache/1.3.37 (Unix) mod_auth_passthrough/1.8 mod_log_bytes/1.2 mod_bwlimited/1.4 FrontPage/5.0.2.2635.SR1.2 mod_ssl/2.8.28 OpenSSL/0.9.7a PHP-CGI/0.1b

Cache-Control: must-revalidate, post-check=0, pre-check=0, private

Content-Disposition: attachment; filename="Lotus_Website_Project.zip"

Content-Transfer-Encoding: binary

Expires: 0

Pragma: public

X-Powered-By: PHP/5.2.2

Content-Length: 71035

Keep-Alive: timeout=60, max=494

Connection: Keep-Alive

Content-Type: application/zip

 

I also tried to open two windows (same browser), both set to my website. Once a download from one browser window begins, the other browser can no longer navigate the website as well.

 

Using two different browser windows however, will work. If I use IE and FF, I don't get the issue. So this is not an IP restriction issue.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.