2011-04-05 33 views
3

我正在使用PHP腳本在您下載文件時下載文件,但無法進行設置,因此當用戶下載文件時將顯示文件大小(我的節目「未知的剩餘時間」)。我在Google上瀏覽過,無法找到如何爲我顯示文件大小,因爲根據所有這些腳本,我做的是正確的。我回顯了文件大小,以確保腳本正確讀取文件,並以字節爲單位返回正確的文件大小。文件大小在下載文件時不會顯示在PHP下載腳本中

$file = 'audio/song.mp3'; 

if(file_exists($file)) { 
    header('Content-description: File Transfer'); 
    header('Content-type: application/force-download'); 
    header('Content-disposition: attachment; filename="' . $songname . '_' . $filetype . '.' . $ext . '"'); 
    header('Content-Transfer-Encoding: binary'); 
    header('Expires: 0'); 
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); 
    header('Pragma: public'); 
    header('Content-Length: ' . filesize($file)); 
    ob_clean(); 
    flush(); 
    readfile($file); 
    exit; 
} 
else { 
    die; 
} 

在此先感謝。


謝謝你,禁用mod_deflate工作。

如果有人在這裏磕磕絆絆,需要弄清楚如何解決它,請將其添加到.htaccess中。

# for URL paths that begin with "/foo/bar/" 
SetEnvIf Request_URI ^/foo/bar/ no-gzip=1 

# for files that end with ".py" 
<FilesMatch \.py$> 
    SetEnv no-gzip 1 
</FilesMatch> 
+1

務必將答案標記爲正確答案。 – Christian 2011-04-05 06:32:20

回答

2

我讀到Apache的「mod_deflate」擴展可能會導致這種類型的腳本出現問題。如果啓用它,則應該禁用該特定腳本。

+0

謝謝你,那很好。 – Kevin 2011-04-05 06:07:10