2013-12-13 27 views
0

我必須在我的網站上顯示一個下載鏈接,將其鏈接到託管在另一個域上的文件。我正在使用以下方法。URL中的重定向屏蔽在PHP中

1)拿起從數據庫

$fileDownloadLink = "http://whatever.com/thefile.docx"; 

2實際的URL)進行編碼的URL,並將其傳遞作爲參數的download.php

$shortUrl = base64_encode($fileDownloadLink); 
<a href="<?php echo "http://www.mydomain.net/download.php?session=".$shortUrl;?>" target="_blank">Download Please</a> 

3)的download.php解碼通過字符串並嘗試閱讀文件。

<?php 
$str = $_GET["session"]; 
$path = base64_decode($str); 
$mm_type="application/octet-stream"; 
header("Pragma: public"); 
header("Expires: 0"); 
header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); 
header("Cache-Control: public"); 
header("Content-Description: File Transfer"); 
header("Content-Type: " . $mm_type); 
header("Content-Length: " .(string)(filesize($path))); 
header('Content-Disposition: attachment; filename="'.basename($path).'"'); 
header("Content-Transfer-Encoding: binary\n"); 
readfile($path); 
exit(); 
?> 

但我從的download.php

不接受收到此錯誤!

在此服務器上找不到所需資源的適當表示 。此錯誤由Mod_Security生成。

請大家幫忙。

回答

0

您可能會重定向到download.php;

$str = @$_GET["session"]; 
$path = base64_decode($shortUrl); 
header("Location: $path"); 
exit();