2013-07-26 118 views
2

我有一個PHP腳本,應該允許用戶下載文件時不顯示URL。當我嘗試以下時,我下載的文件是空的。有人可以幫忙嗎?如何隱藏下載鏈接

<?php 
$file_name = 'test.exe'; 
$file_url = 'https://www.example.com/' . $file_name; 
header('Content-Type: application/octet-stream'); 
header("Content-disposition: attachment; filename=".$file_name); 
readfile($file_url); 
?> 
+0

example.com是您的網站還是遠程位置? – JohnnyFaldo

+0

看到http://stackoverflow.com/questions/7263923/how-to-force-file-download-with-php – andrewb

回答

2

你應該使用這樣

header("Content-Type: application/octet-stream"); 
header("Content-Transfer-Encoding: Binary") 
header("Content-disposition: attachment; filename=\"file.exe\""); 
echo readfile($url); 

也是內容類型基於文件的應用程序/ ZIP,應用/ PDF等

AND或更好的一個EXE

header("Location: $url"); 
+0

我不能讓它與第一種方法一起工作,但使用「位置」的第二種方法似乎工作好。謝謝。 –

+0

是的,我的申請是在 – liyakat

+0

之前工作現在又出現了第二個問題。使用這種新技術,似乎用戶仍然可以在DAP等下載管理器中看到下載鏈接。那麼真的有辦法隱藏URL嗎? –