Please see the screenshot below. When someone is downloading files from my site it, while downloading size is not showing. Thus, users cannot know how much is remaining, what is the size. Can someone help me or tell any idea to fix this? Is this a problem with the server? Or I have to put any code or something?
Asked
Active
Viewed 1,023 times
0
-
Probably, your site is not sending the file size in the header for your download. What you do about that is dependent on your site and the download code - there's nothing here to be able to diagnose it. – May 10 '14 at 05:44
-
I now notice that you asked this question two days ago and got exactly this answer, which you accepted. Why are you asking again? – May 10 '14 at 05:46
-
@MikeW but it was not actually helpful. That answer is only for one file. My site have lots of downloads like this. – Gijo Varghese May 10 '14 at 05:59
-
Then you should have explained that rather than asking the same vague question. – May 10 '14 at 06:09
1 Answers
1
You should properly send the headers from your server Better look at this :- http://php.net/manual/en/function.readfile.php
Example
<?php
$file = 'yourfile.apk';
if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file));
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
exit;
}
?>

poush
- 273
- 1
- 10
-
-
create a page like download.php and paste this code there and pass the file name as a GET or POST parameter so that your download.php will know the file to send and everything will be same like $filename = $_GET['file']; Also keep all files in same directory so that you can easily access them. Also if you have file not in root directory of download.php you can link it within code. For example if file is in files folder from download.php then $file = 'files/'.$_GET['file']; – poush May 10 '14 at 06:11
-
@ that is really helpful. One more doubt. What is the file extension is .exe or something like that? i can use the same code right? only change the file name. ok? – Gijo Varghese May 10 '14 at 06:26
-
Yes of course. But don't forget to sanitize the get parameter. You can use pathinfo() function like pathinfo($_GET['file']) which will also separate the extension of file and name of requested file. For more information you should check out first example of documentation which purely describes how you can use this function http://php.net/manual/en/function.pathinfo.php – poush May 10 '14 at 12:27
-
-