2012-12-29 17 views
0

我想打一個鏈接,下載和我所有的文件其實是zip但idont希望我的用戶知道哪裏是我的下載鏈接得到一個zip文件的內容,並將它顯示給用戶

,所以我想要得到的內容zip文件並用zip標題回顯給用戶可以下載它,我該怎麼做?

+0

檢查這個問題,它的答案[鏈接](HTTP:/ /stackoverflow.com/questions/3599056/best-way-to-read-zip-file-in-php) – ECode

回答

0

您應該使用「download.php?get =」。 base64_encode($ filename) 當用戶點擊「下載zip」時,您將其重定向到標題(「Location:download.php?get =」。base64_encode($ url)到該頁面 標題,這裏我們去

$filename = base64_decode($_GET[get]); 
$filepath = "/var/www/domain/httpdocs/download/path/"; 

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: application/octet-stream"); 
header("Content-Disposition: attachment; filename=\"".$filename."\""); 
header("Content-Transfer-Encoding: binary"); 
header("Content-Length: ".filesize($filepath.$filename)); 
ob_end_flush(); 
@readfile($filepath.$filename); 
+0

Ps如果你想讓下載鏈接唯一,只需添加「&u = base64_encode(time())」,然後解碼字符串並限制下載可訪問性,比如說10分鐘。 – djpredator17

+0

我的firend我嘗試這個,但是當文件準備好下載它的節目0字節,我確定我的目標(文件路徑是好的).... –

0

而是用頭,你可以嘗試下載一些「準備使用」 php class那麼你可以做類似實驗的:!

$fileDown = new PHPFileDownload(null, null, 'myFileName', null, 'mypath/myfile.txt'); 
$fileDown->exportData(); 
相關問題