Reputation: 2984
Is there a difference between directly downloading a file from a web server, and downloading the same file through a PHP script that uses these headers? (Assume that all of the variables here contain correct values for the file being downloaded.)
header('Content-Description: File Transfer');
header('Content-Type: ' . $mimeType);
header('Content-Disposition: attachment; filename='.basename($file));
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($file));
After reading the discussion here, i want to change the question :
With a file on server for user who can download.
What & when do we need to process this task by PHP script?
Same question with direct link of file
Upvotes: 2
Views: 439
Reputation: 21229
I would think this would also let you create a download for a resource that is normally forbidden for a user to directly access. It also seems like you could use this for a file that only exists in memory, without having to write it out to disk first.
Upvotes: 1
Reputation: 33227
If your "normal" download would supply those exact headers, then no.
However, a number of things could cause the server to decide to send different headers:
Upvotes: 3
Reputation: 522523
Not as far as the client is concerned, no.
The difference for the server is that you have the full power of PHP to do something with before initiating the download, which is not the case if Apache handles the download directly. It also means that the whole cruft of PHP needs to be loaded and executed before a download can start and it'll occupy one PHP process until the download is finished.
Upvotes: 3