I've once found this code to serve images from my server to the client:
$filename = $_GET["filename"];
if ($filename == null || strlen($filename) < 1){
return null;
}
$fp = fopen($filename, 'rb');
// send the right headers
header("Content-Type: image/jpeg");
header("Content-Length: " . filesize($filename));
// dump the picture and stop the script
fpassthru($fp);
exit;
When I run this php file via the browser (like call this script in the addressbar of the browser), a portrait image shows portrait.
But when I run this in an HTML file (I set the src
of an img
element dynamically) all portrait images are shown landscape (like rotated 90 degrees).
Should I include something in the response(-headers) that the image is landscape or portrait?
This is the way I load the image in the html:
document.getElementById('next').src = "image.php?filename=" + data;
This is what the request looks like when it's called from my html page and when the image shows correct:
And this is the incorrect version
I can see the headers differ, but does that make a difference? (besides I would know how to set the headers when I set the image source)
One thing I also noticed was that in both cases, when I rightclick and save the image, the filename is image.jfi
which I think is a weird extension?