2013-03-07 57 views
-1

我有一個問題,我不知道是否有解決方案。隱藏主要下載網址

我的問題是,我有一個下載鏈接這樣的:

http://remotewebsite.com/file.zip 

該文件是在其他網站上託管不是我的。 ,我想用戶下載文件時不知道原始URL 像例如,當用戶進入我的鏈接

http://mywebsite.com/file.zip 

它開始下載文件。

想象一下,就好像我是承載文件的網站和用戶之間的隧道。 例如,每個來自遠程網站的數據包用戶請求都會經過我,然後發送給用戶。

我不知道是否有另一種簡單的方法來做到這一點。

我很抱歉,如果它聽起來啞巴,但我真的希望它可以工作。

+1

可以使用Apache的代理功能來設置這樣的隧道,但您需要對您的服務器進行根訪問才能設置它們。 – 2013-03-07 16:48:10

回答

6

只需使用CURLfile_get_contents即可獲取文件的內容,並使用相應的標頭文件將其輸出到瀏覽器。

header('Content-Description: File Transfer'); 
header('Content-Type: application/zip'); 
header('Content-Disposition: attachment; filename=file.zip'); 
header('Content-Transfer-Encoding: binary'); 
header('Expires: 0'); 
header('Cache-Control: must-revalidate'); 
header('Pragma: public'); 
ob_clean(); 
flush(); 
echo file_get_contents("http://remotewebsite.com/file.zip"); 
+0

非常感謝你的回答,但我是新手到PHP我會愛如果你能給我一個簡單的代碼。 – BOSS 2013-03-07 16:50:36

1

您可以使用URL重寫機制路由到一個PHP腳本,將從遠程服務器下載真正的文件,並將其投放到您的客戶端的所有請求file.zip

如果你指定你使用的平臺(Apache/IIS),我可以提供詳細的例子來說明如何實現它。

對於IIS 7或更高版本,在您的web.config文件中使用此:

<configuration> 
<system.webServer> 
    <rewrite> 
     <rules> 
      <rule name="file.zip" patternSyntax="ExactMatch" stopProcessing="true"> 
       <match url="file.zip" /> 
       <action type="Rewrite" url="download_zip.php" /> 
      </rule> 
     </rules> 
    </rewrite> 
</system.webServer> 
</configuration> 

"download_zip.php"使用PHP代碼 「nauphal」 這裏contirbuted。

+0

我有一個共享主機Apache和IIS – BOSS 2013-03-07 16:52:48