先確定把一個 jpg 檔案抓出來看看能不能運作吧.
三個檔案 t.html, getpic.php, t.jpg
t.html:<html>
<head><title>Test Jpeg</title></head>
<body>
<img src="getpic.php">
</body>
</html>
getpic.php:<?php
header("Content-Type: image/jpg");
header("Content-Disposition: inline");
echo file_get_contents("t.jpg");
exit;
?>
這個我試過是可以顯示出正確的圖片.
先找一個正常的圖片來看看. (不要用你資料庫抓出來的)
如果可以 (不行我就不知道了, 也許你的 php 檔案有問題吧 (utf8? BOM?), 再把這個檔案用 base64 編碼後寫到資料庫. 然後再解碼寫成另一個檔案.
先確定讀出來的檔案與之前的一模一樣 (不一樣? 一定是中間過程有問題, 因為 base64 是可逆的, 編碼再解碼後一定是一樣的東西).