2

I am running a blog on WordPress. For downloading some files from my blog, first I upload the files to my server in the folder /downloads. Then I link the file in my post. When a user clicks the download button, the download starts. But the problem is it doesn't show how much is the file size. It only shows how much is downloaded. I have provided a link below to check.

The site is in Wordpress. Hosted on Godaddy.

Sample post (pls check the download link) : http://www.tekyfox.com/android/bug-fixed-moto-g-boot-animation-change-updating/

Gijo Varghese
  • 11,264
  • 22
  • 73
  • 122
  • Did you send the filesize header? http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.13, apparently you did not: http://pastebin.com/vT8s25K9 – Flosculus May 07 '14 at 12:37
  • @Flosculus the link is not opening. Can you pls describe me what it is, or send me any other useful link. Thanks for the help – Gijo Varghese May 07 '14 at 12:39
  • It downloaded too quickly for me to see if it knew the file length. Did you hand write the download script? – Flosculus May 07 '14 at 12:41
  • @Flosculus what is download script? Where should I put it? Is it common for all files? Because my blog will have several download links like this in future... – Gijo Varghese May 07 '14 at 12:45
  • I'm having the same problem. Did you find a solution? – Paras Sidhu Jan 28 '17 at 08:07
  • Yes!! Check the answer – Gijo Varghese Jan 28 '17 at 08:08
  • @GijoVarghese I have the same problem as him. I have over 100 files. I can't create PHP files for all different files. I think there's some alternative solution too because most websites link downloads like: yourdomain.com/file.pdf and not yourdomain.com/file.php – Paras Sidhu Jan 28 '17 at 09:06
  • I think what you can do is, create a php file that 'GET's the file name and finds its size and then echo it. Since its using get method, you can send any file to that script. So your download link will be like: https://sample.com/downloader.php?file=some1.exe or https://sample.com/downloader.php?file=some2.exe Got it? – Gijo Varghese Jan 28 '17 at 11:07
  • Sorry, I don't prefer this method. When size is shown for http://media.askvg.com/downloads/2017/01/Clear-Desktop-Background-History-in-Windows-10-Settings.zip, why shouldn't it be shown on my website? I think I should make a new thread – Paras Sidhu Jan 28 '17 at 13:10

3 Answers3

9

Thank you a ton Rich. It worked for me! I followed the link you provided: "File Downloads from Apache Server Doesn't Show Total". The first answer given there says to add the following line in .htaccess file:

SetEnv no-gzip dont-vary

That's it! It did the trick. Thank you very much again. It was a huge headache since last 4-5 days.

Community
  • 1
  • 1
Paras Sidhu
  • 652
  • 1
  • 12
  • 36
2

Create a PHP file locally, with this:

$file = file_get_contents('http://www.tekyfox.com/downloads/motorola_boot_animation.apk');

header('Content-Disposition: attachment; filename=test.apk');
header('Content-Type: application/vnd.android.package-archive');
header('Content-Length: '.strlen($file));

echo $file;

Make another file with a button link to that local PHP file. See if you get the same problem. If not, it may be because the browser doesn't know the file size until the server closes the connection.

Flosculus
  • 6,880
  • 3
  • 18
  • 42
  • but I will have a lot of apk files like this. I can't create PHP files for each apk file. Any other easy methods? – Gijo Varghese May 07 '14 at 12:51
  • Well, without tests we don't know what the problem is, so right now there is no easy solution. All I know is there is a path called `/downloads` and there are files or getters after it. Update your questions further detailing what the problem is, how the files are accessed (and I don't mean by the user) and what is expected. – Flosculus May 07 '14 at 12:57
1

If you are linking directly to the file in a "downloads" dir or similar, then this is not a PHP issue, but an issue with the configuration of your webserver (i.e. Apache or nginx).

See https://superuser.com/questions/617327/why-do-some-downloading-files-not-know-their-own-size for a discussion of the mechanics and HTTP headers involved.

To fix this for you, we will need to know:

  • What web server you are using (Apache?) and its version
  • The HTTP headers that are being sent from the server when the file is downloaded (you can get these with curl, e.g. curl -v http://..., or in Chrome devtools)

Some similar questions which may answer your problem:

Community
  • 1
  • 1
Rich
  • 15,048
  • 2
  • 66
  • 119