For example: There is a website which offers file downloads. The website and downloadable files are on separate servers. When a user attempts to download a file, the file server sends the file instead. The file server should not have to send the file to the website's server first before arriving at the user, since that would use double the bandwidth.
Can PHP be used to serve the file directly from the file server?
Note: a single server setup can simply use the following code from the PHP manual. I need these headers to be sent from the file server directly to the user.
<?php
$file = 'monkey.gif';
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));
readfile($file);
exit;
}
?>