I have got an SQLite3 Database with several image开发者_如何学编程s in it. I want to display these Images in a Browser (Images are fetched from DB via PHP Script).
header('Content-type: image/jpeg');
$img=$this->getImgData($mid);
//next line is just for testing purposes
file_put_contents("/tmp/thumb.jpg", $img);
echo $img;
exit();
The Problem is: The Image /tmp/thumb.jpg can be viewed by any image Viewer, but the browser calling this php script (which gets the exact same data as in /tmp/thumb.jpg) refuses to display it. How could that be?
Make sure not to have any characters written before this section
Most of the time there are spaces before a <?php
, or in an include file somewhere above.
Doublecheck that!
Other than that everything look fine. IMO it should work.
Found the Problem: I copied the content type from a webpage to my IDE.
header('Content-type: image/jpeg');
It seems like the "space" between "Content-type:" and "image/jpeg" wasn't a space but rather any other invisible unicode char. So i just keyed in the header by hand - and it worked!
精彩评论