I am using php's imagejpeg to save a GD image resource to a file, doing this:
imagejpeg($im, '../images/' . $image_id . '.jpg');
It works fine, but according to my browser, it tries to read the file as text/plain:
Resource interpreted as image but transferred with MIME type text/plain.
Is there a step before saving the file that I am supposed to do to make sure it's 开发者_如何学运维using the right mine-type?
I am using windows (XAMPP), could it be a Windows issue? EDIT: nope. I just tested in a linux server.
As far as the actual displaying, it's just plain html . My upload code is supposed to saves= the file as a plain jpeg in the server. It's just not saving it with the right mime type.
Thanks
AFAIK, the Apache server - in standard out of the box configuration - should sent content-type headers purely based upon file extension. Apache shouldn't even even be looking at the contents or how it was originally generated/stored.
On my out-of-the-box Apache2, the file conf/mime.types contains the line:
image/jpeg jpeg jpg jpe
which ought to do it, right?
Can you post a test-case, say, a simple html page with two img tags: one for your generated image, and one for a standard image that seems to work fine?
One last thought: Does it occur in all browsers? Maybe it's a browser issue, not a server one?
It sounds like you're dumping the contents of the file to the browser and not actually telling the browser what type of file it is. Try adding a Content-type header before you output your image to the browser:
header('Content-type: image/jpeg');
Are you sure you aren't using the wrong file-extension name? Otherwise, just put an normal image in the server and make sure the mime-types are properly configured. It could also be that your image data from the manipulation is corrupted.
精彩评论