2013-06-18 110 views
-4

我正面臨下載腳本的問題,無論何時下載到我的項目網站上,網站上的所有鏈接都不起作用。 一旦文件完全下載,鏈接開始工作。面向PHP下載腳本的問題

我在設置header和使用readfile方法php下載文件。我希望該文件下載應與用戶在網站上的操作同時工作。 我使用下面的代碼

header("Pragma: public"); 
    header("Expires: 0"); 
    header("Content-Type: application/$ctype"); 
    header("Content-Description: File Transfer"); 
    header("Content-Disposition: inline; filename=$docName"); 
    header('Content-Length: '. filesize($filename)); 
    header("Accept Ranges: bytes"); 
    header("Content-Transfer-Encoding: binary");   
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");    
    readfile("$filename"); 

這裏filename是文件的名稱和ctype是文件類型。

如何解決這個問題?

請讓我知道是否有人有解決這個問題。

+1

得到任何代碼向我們展示任何文件? – ChrisW

+0

許多人只有在能夠第一時間瞭解問題時纔會有解決方案,所以請幫助我們解決您的問題 –

回答

0

我只是猜測,你缺少一個適當的標題,因爲你需要

$下載更改內容類型和傳輸編碼是實際的文件即/var/www/download_images/1.jpg

$文件大小是文件

$文件名的大小可以是你希望呈現給用戶,即homer_simpson.jpg

<?php 
    if (file_exists($download)) 
    { 
     header("Cache-Control: must-revalidate"); 
     header("Expires: 0"); 
     header("Pragma: public"); 
     header("Content-Description: File Transfer"); 
     header("Content-Length: ". $filesize .";"); 
     header("Content-Disposition: attachment; filename=" . $filename); 
     header("Content-Type: application/octet-stream; "); 
     header("Content-Transfer-Encoding: binary"); 
     ob_clean(); 
     flush(); 

     readfile($download); 
    } 
?>