0

I have a rather simple force download script:

$thefile = $_GET['id'];
$file = 'http://www.mywebsite.com/test/'.$thefile;
header('Content-Disposition: attachment; filename='.$thefile); 
header("Content-Type: application/force-download");
@readfile($file);

And it works nicely, except it does not show how much time is remaining ("could not calculate time").

I found someone with a similar problem here, by using this code:

# for URL paths that begin with "/foo/bar/"
SetEnvIf Request_URI ^/foo/bar/ no-gzip=1

# for files that end with ".py"
<FilesMatch \.py$>
    SetEnv no-gzip 1
</FilesMatch>

But alas, I can not get that to work. My files are media files (avi, wmv, mp4 and so forth), so I assumed I would have to modify the code along these lines:

SetEnvIf Request_URI ^/test/ no-gzip=1

<FilesMatch "\.(avi|wmv|mp4|mpg|mpeg|m4v)$">
    SetEnv no-gzip 1
</FilesMatch>

I have also changed the path to a simple test folder, but time is still not being displayed.

How to?

Community
  • 1
  • 1
Emily Adler
  • 73
  • 2
  • 12

1 Answers1

0

You should add content-length header, for your browser to know total file size.

header("Content-Length: " . filesize($file));

Take a look at this example.

Pavel Strakhov
  • 39,123
  • 5
  • 88
  • 127
  • Thank you, but I have tried that (header("Content-Length: " . filesize($file));) but to avail. – Emily Adler May 12 '13 at 10:35
  • @EmilyAdler Disabling GZIP and returning Content-length should do the trick. If it doesn't- check the headers returned by your server to your browser. For Firefox there is a nice plugin called Tamper Data. – Tom May 12 '13 at 11:25