2009-11-10 48 views
0
if(preg_match('/^[a-zA-Z0-9]+\.(gif|jpe?g)$/',$row['filename'],$matches) && 
    is_readable($row['filepath'].$row['filename'])){  
    echo header('Content-Type: image/'.$matches[1]);  
    echo header('Content-Length: '.filesize($row['filepath'].$row['filename']));  
    echo file_get_contents($row['filepath'].$row['filename']); 
} else { 
    echo 'cant serve image: '.$row['filename']; 
} 

當我嘗試放置header('Content-Type': image/jpeg)例如,它只顯示一個空白頁和當前的網址。圖片不顯示使用讀取文件/ file_get_contents

我試圖顯示一個圖像來代替我的<img>標籤。

filepath包含圖像目錄的物理路徑。

回答

0

您不需要echo header,只需header

1

不知道它會解決整個問題,但你不應該使用echoheader函數的返回值:發送一個報頭,只需要使用header功能,並沒有任何迴音:

header('Content-Type: image/'.$matches[1]); 

無效的圖像(IE,火狐顯示它的網址,而不是它的內容)往往是由無效輸出造成危害/圖像日期後 - 確保你沒有什麼發送到比其他瀏覽器圖像本身。