例如:有一個提供文件下載的網站。網站和可下載文件位於不同的服務器上。當用戶嘗試下載文件時,文件服務器會改爲發送文件。文件服務器在到達用戶之前不應該首先將文件發送到網站的服務器,因爲這會使用兩倍的帶寬。Apache/PHP可以從另一臺服務器提供文件嗎?
可以使用PHP直接從文件服務器提供文件嗎?
注意:單個服務器設置可以簡單地使用PHP手冊中的以下代碼。我需要將這些標題從文件服務器直接發送給用戶。
<?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;
}
?>
爲什麼不直接將用戶重定向到文件服務器?例如:他點擊了網站1上的一個按鈕,將他重定向到:http://website2/files/foo.bar? –
也許:http://stackoverflow.com/questions/6086231/transfer-from-server-server-client-without-download-to-server/6086311#6086311也http:// stackoverflow。COM /問題/ 10991443 /捲曲得到遠程文件和力下載-AT-同一時間/ 10993094#10993094 –