2012-02-11 44 views
0

圖像下載不起作用。它直接讀取而不是下載。圖像下載不起作用。它直接讀取

if($_REQUEST['image'] == true){ 

    $URl = $post->guid; 
    echo $URl; 
    header("Content-Type: image/png"); 
    header('Content-Description: File Transfer'); 
    header("Cache-Control: no-cache, validated"); 
    header('Content-Type: application/octet-stream'); 
    header("Content-Disposition: attachment; filename=\"".basename($URl)."\""); 
    header('Content-Transfer-Encoding: binary'); 
    var_dump(readfile($URl)); 
    die; 
} 
+0

[變量是大小寫敏感的(http://php.net/manual/en/language.variables.basics.php)。將'$ URl'更改爲'$ URL'(注意Ls?)。 – Josh 2012-02-11 06:18:11

+0

我做了,但沒有工作.... – ayyan 2012-02-11 06:36:25

+0

什麼是「不工作」? – zerkms 2012-02-11 06:45:14

回答

0

嘗試這個報頭格式,

header("Content-type: application/octet-stream"); 
header("Content-Length: " . filesize($filename)); 
header("Content-Disposition: attachment; filename=$filename"); 
header('Content-Transfer-Encoding: binary'); 
header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); 
fpassthru($fp); 
+0

Avinash我替換,但現在我也得到了一個相同的輸出閱讀圖像,直接它不會得到下載...... – ayyan 2012-02-11 06:51:09

+0

更新內容類型爲「application/octet-stream」。因爲你不能保證彈出框,這一切都取決於客戶端的browswer軟件如何處理這種特定的MIME類型。 – Avinash 2012-02-11 07:10:54

+1

將圖像鏈接到一個zip文件,然後它會下載。 – 2012-02-11 19:32:40