简体   繁体   English

php imagejpeg MIME类型

[英]php imagejpeg mime type

I am using php's imagejpeg to save a GD image resource to a file, doing this: 我正在使用php的imagejpeg将GD图像资源保存到文件中,执行以下操作:

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. 资源被解释为图像,但使用MIME类型的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? 我正在使用Windows(XAMPP),这可能是Windows问题吗? EDIT: nope. 编辑:不。 I just tested in a linux server. 我刚刚在Linux服务器上进行了测试。

As far as the actual displaying, it's just plain html . 就实际显示而言,它只是纯html。 My upload code is supposed to saves= the file as a plain jpeg in the server. 我的上传代码应该将文件另存为服务器中的纯jpeg。 It's just not saving it with the right mime type. 只是没有以正确的mime类型保存它。

Thanks 谢谢

AFAIK, the Apache server - in standard out of the box configuration - should sent content-type headers purely based upon file extension. AFAIK,Apache服务器-在开箱即用的标准配置下-应该纯粹基于文件扩展名发送内容类型标头。 Apache shouldn't even even be looking at the contents or how it was originally generated/stored. Apache甚至都不应该查看内容或它最初是如何生成/存储的。

On my out-of-the-box Apache2, the file conf/mime.types contains the line: 在我现成的Apache2上,文件conf / mime.types包含以下行:

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? 您能否发布一个测试用例,例如一个带有两个img标签的简单html页面:一个用于您生成的图像,另一个用于似乎可以正常工作的标准图像?

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: 在将图像输出到浏览器之前,请尝试添加Content-type标头:

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. 否则,只需在服务器中放置普通映像,并确保正确配置了mime类型。 It could also be that your image data from the manipulation is corrupted. 也有可能是您的图像数据被破坏了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM