I have seen an error which seems extremely weird to me.
http://www.shrimadrajchandramission.org/grace/downloads/wallpapers/images/download.php?wp=SRM-Wallpaper-36-highres.jpg
On my browser, the above link shows 8.4 MB download file size
http://www.shrimadrajchandramission.org/grace/downloads/wallpapers/images/download.php?wp=SRM-Wallpaper-36-highres.jpg&
While this one shows 15.3 MB download file size.
I want to understand if the Server itself caches in some manner, because I had my Hard Disk Replaced recently so I have installed browsers on fresh OS, but it still shows the old filesize (and when you download it, half of it is corrupt-gray color).
download.php on the server has these Headers set:
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Last-Modified: '.gmdate ('D, d M Y H:i:s', filemtime ($file_name)).' GMT');
header('Cache-Control: private',false);
header('Content-Type: image/jpg');
header('Content-Disposition: attachment; filename="'.basename($file_name).'"');
header('Content-Transfer-Encoding: binary');
header('Content-Length: '.filesize($file_name));
I am now using a JavaScript Date Function to get the file afresh from the server. So my current issue is resolved, but I am trying to understand what is happening behind the scene.
If you are unable to reproduce this issue, then what could be the issue on my computer specifically? I have at least one person whom I know facing the same scenario.
Thanks!
Related
I'm using the following code to check if a user has permission to download a file and to log that s/he downloaded it. It works good, but the files are hosted on Dropbox and I assume that the files are downloading through my server? I have recently gotten CPU spikes and complete server stalls so I'm looking into the option of either optimizing my code below if possible, or make so the access check and download count happens and then you're redirected to the dropbox link. Any suggestions?
<?php
/* PHP code here (not included in this snippet) to check for access and log download */
session_write_close();
header("Cache-control: private");
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"file.mov\"");
header('Content-Transfer-Encoding: binary');
// Disable caching
header('Cache-Control: no-cache, no-store, must-revalidate'); // HTTP 1.1.
header('Pragma: no-cache'); // HTTP 1.0.
header('Expires: 0'); // Proxies.
readfile('https://dropboxlink...');
exit;
?>
I have a website that offer downloads of some large files, up to 10gb.
There is an issue with the downloads that doesn't happen to me, and actually doesn't happen to most of my users, but I keep getting messages from some users that their downloads stop at 2gb, and the file is larger that that.
I serve the downloads using nginx XSendfile with php:
header('X-Accel-Cache-Control: no-store, no-cache, must-revalidate');
header('Pragma: no-cache');
header('Content-Type: application/octet-stream');
header('Content-Length: ' . $this->getFileSize() );
header('Content-Disposition: attachment; filename="' . $fileName . '"');
header('Accept-Ranges: bytes');
header('X-Accel-Buffering: yes');
header('X-Accel-Redirect: ' . $this->getServeDownloadLocation());
Running on CentOS 6.6, php 5.5.22, nginx 1.6.2.
Notice: the users don't use old browsers, they use modern browsers like Google Chrome.
I have a little script which sets the header to force download of a zip file with:
if(ini_get('zlib.output_compression')) {
ini_set('zlib.output_compression', 'Off');
}
header("Pragma: public");
header('Expires: '.gmdate('D, d M Y H:i:s').' GMT');
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false);
header("Content-Description: File Transfer");
header("Content-type: application/octet-stream");
header('Content-Disposition: attachment; filename="'.$mp3.'"');
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".#filesize($file));
#readfile($file) OR die("<html>...</html>");
exit;
Everything works fine in Chrome and Firefox but fails in IE 9. I have tried many different ways of setting those headers after googling around but nothing helps. Then I tried a different smaller zip file and it worked! Then I tried a bigger zip file and again fail. Would this be some setting on the server or the php.ini or something? Why does it only affect IE?
When it fails in IE it looks like it downloads.. says completed. But the file is 0 bytes.
Thanks for any help!
If the file is large enough you may have issues related to memory, execution time, etc.
Instead of trying to read the file, you could use the x-sendfile header:
header('x-sendfile: '.$file);
Check out this article about it: http://www.jasny.net/articles/how-i-php-x-sendfile/
I have uploaded a .mp4 file with php in a upload folder. Now i am downloading it with download link. It is downloading properly on a windows system in safari browser. But on mac system the video file is playing with quicktime pro player. While i just want to download it.
but it is playing by default. It is the issue only on safari browser. Is there any way to change this. so that it will not play with quicktime pro player by default.
That's probably because you're just linking to the file so if the user's computer has software to handle it, it will choose to run it by default (assuming the user has their computer set up that way).
You can force the browser to show the download dialog prompt if you use the proper headers:
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=$file");
header("Content-Type: video/mpeg");
header("Content-Transfer-Encoding: binary");
Please use the following code,
if (file_exists($file)) {
header('Pragma: public'); // required
header('Expires: 0'); // no cache
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Last-Modified: '.gmdate ('D, d M Y H:i:s', filemtime ($file)).' GMT');
header('Cache-Control: private',false);
header('Content-Type: octet/stream');
header('Content-Disposition: attachment; filename="'.basename($file).'"');
header('Content-Transfer-Encoding: binary');
header('Content-Length: '.filesize($file)); // provide file size
header('Connection: close');
readfile($file); // push it out
exit();
}
I have a PHP file that serves up a file, but the problem is that no matter what browser is being used, if you click on 2 links that go to 2 separate files, the second download doesn't start until the first one is complete! Any ideas?
Download Code
header('Content-Type: application/octet-stream');
header('Content-Description: File Transfer');
header('Content-Disposition: attachment; filename="'.basename($filename).'"');
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($fullpath));
readfile($fullpath);
Example Links
Link 1: download.php?downloadfile=1
Link 2: download.php?downloadfile=2
There could be different reasons for this.
You are using sessions. Therefor only one script at a time is allowed to modify the session. So download B can only start after download A has finished. Did you try two downloads concurrently with download A in browser A and download B in browser B? Check description for session_write_close
Some other HTTP issue where your browser won't open multiple connections to the server but reuse a single connection and that way of course has to wait until first request finishes.
Some OS/Webserver setting which only allows a very limited number of open concurrent connections either in total or per host