顯示資料庫中blob類型的圖片,我圖片顯示不出來

來源:互聯網
上載者:User
showimage.php
query($sql );$query_num = $SqlHelper->num_rows ($query );$rows = array ();  $retarr = array (); $query =$SqlHelper->query ( $sql );if($query){$arr_teainfo2 = array ();while ( $arr_teainfo = $SqlHelper->fetch_assoc($query) ) {$arr_teainfo2 [] = $arr_teainfo;$Id=$arr_teainfo["Id"];echo $arr_teainfo["Id"];echo ""; }}?>  


Second.php3
query($sql );$query_num = $SqlHelper->num_rows ($query );$rows = array ();  $retarr = array (); $query =$SqlHelper->query ( $sql );if($query){$arr_teainfo2 = array ();while ( $arr_teainfo = $SqlHelper->fetch_assoc($query) ) {$arr_teainfo2 [] = $arr_teainfo;$Id=$arr_teainfo["Id"];$imagetype=$arr_teainfo["imagetype"];//echo $arr_teainfo["images"];//Header( "Content-type: $imagetype"); header('Content-type: $imagetype');echo $arr_teainfo["images"];}}?>   


請問我哪裡有問題?PHP新人,不知道哪裡錯了


回複討論(解決方案)

1、你的 php3 類型檔案能被正確解析嗎?檢查一下設定檔
2、如果程式檔案時 utf-8 編碼的,請確認都沒有 BOM 頭
3、Second.php3 輸出圖片不要用迴圈

1、你的 php3 類型檔案能被正確解析嗎?檢查一下設定檔
2、如果程式檔案時 utf-8 編碼的,請確認都沒有 BOM 頭
3、Second.php3 輸出圖片不要用迴圈
我在httpd.conf檔案裡面加了AddType application/x-httpd-php .php .html .htm .php3
這樣是不是就能正常解析php3 類型檔案了?

1、你的 php3 類型檔案能被正確解析嗎?檢查一下設定檔
2、如果程式檔案時 utf-8 編碼的,請確認都沒有 BOM 頭
3、Second.php3 輸出圖片不要用迴圈
我程式檔案是gbk的

我測試了,.php3可以正常解析的,但是還是不行啊誰幫下啊

圖片顯示不出來,是程式報錯?還是路徑不對。
先列印下,看有資料沒,如果有,再看下,顯示的路徑是否正確。

圖片顯示不出來,是程式報錯?還是路徑不對。
先列印下,看有資料沒,如果有,再看下,顯示的路徑是否正確。
先運行php3把image列印出來了,正常的,沒有報錯

query($sql );$query_num = $SqlHelper->num_rows ($query );$rows = array ();  $retarr = array (); $query =$SqlHelper->query ( $sql );if($query){$arr_teainfo2 = array ();while ( $arr_teainfo = $SqlHelper->fetch_assoc($query) ) {$arr_teainfo2 [] = $arr_teainfo;$Id=$arr_teainfo["Id"];$imagetype=$arr_teainfo["imagetype"];$image= $arr_teainfo["images"];}//header('Content-type: image/jpeg ');echo $image; }

上面代碼貼出來多了

,我程式裡沒有的


圖片顯示不出來,是程式報錯?還是路徑不對。
先列印下,看有資料沒,如果有,再看下,顯示的路徑是否正確。
先運行php3把image列印出來了,正常的,沒有報錯

query($sql );$query_num = $SqlHelper->num_rows ($query );$rows = array ();  $retarr = array (); $query =$SqlHelper->query ( $sql );if($query){$arr_teainfo2 = array ();while ( $arr_teainfo = $SqlHelper->fetch_assoc($query) ) {$arr_teainfo2 [] = $arr_teainfo;$Id=$arr_teainfo["Id"];$imagetype=$arr_teainfo["imagetype"];$image= $arr_teainfo["images"];}//header('Content-type: image/jpeg ');echo $image; }

程式沒報錯,把輸出的資料複製到地址欄,有圖片顯示沒??



圖片顯示不出來,是程式報錯?還是路徑不對。
先列印下,看有資料沒,如果有,再看下,顯示的路徑是否正確。
先運行php3把image列印出來了,正常的,沒有報錯

query($sql );$query_num = $SqlHelper->num_rows ($query );$rows = array ();  $retarr = array (); $query =$SqlHelper->query ( $sql );if($query){$arr_teainfo2 = array ();while ( $arr_teainfo = $SqlHelper->fetch_assoc($query) ) {$arr_teainfo2 [] = $arr_teainfo;$Id=$arr_teainfo["Id"];$imagetype=$arr_teainfo["imagetype"];$image= $arr_teainfo["images"];}//header('Content-type: image/jpeg ');echo $image; }

程式沒報錯,把輸出的資料複製到地址欄,有圖片顯示沒??
這個存的不是圖片的地址,而是blob資料類型的

瀏覽器地址欄 http://localhost/Second.php3?Id=10
能開到什嗎?

瀏覽器地址欄 http://localhost/Second.php3?Id=10
能開到什嗎?
如果有header('Content-type: image/jpeg ');的話,是一個顯示叉叉的圖片,就是顯示不出來,如果注釋掉,就是執行echo $image; ,顯示的是好多看不懂的符號亂碼,因為是blob類型,肯定不能正常輸出的

瀏覽器地址欄 http://localhost/Second.php3?Id=10
能開到什嗎?
我測試的id為10的圖片是jpg的,所以我先寫出固定的header('Content-type: image/jpeg ');

一大堆亂七八糟的?沒關係,截個圖

截個圖都卡半天

下面還有好多好多

一大堆亂七八糟的?沒關係,截個圖 能看懂嗎,那些亂七八糟的,不知道什麼東西

你的圖片格式有問題!

這樣吧,你把 $image 寫到檔案裡,比如 file_put_contents('test.jpg', $image);
然後把他發上來

 

我的原始版代碼。
是pjpeg哦。

你的圖片格式有問題!

這樣吧,你把 $image 寫到檔案裡,比如 file_put_contents('test.jpg', $image);
然後把他發上來
前幾天放假了,昨天請假了,等下我傳上去

你的圖片格式有問題!

這樣吧,你把 $image 寫到檔案裡,比如 file_put_contents('test.jpg', $image);
然後把他發上來
可以正常寫入的

原來 test.jpg是另一張圖,寫入後就是這張圖了

 

我的原始版代碼。
是pjpeg哦。
我用pjpeg還是顯示不出來,我用的gbk的格式,請問你用的什麼格式?
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.