2013-07-26 78 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吗? –