Size not showing while downloading files from my w

2019-02-20 09:08发布

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/

3条回答
仙女界的扛把子
2楼-- · 2019-02-20 09:39

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.

查看更多
地球回转人心会变
3楼-- · 2019-02-20 09:53

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.

查看更多
smile是对你的礼貌
4楼-- · 2019-02-20 09:57

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:

查看更多
登录 后发表回答