我可以在< img>中使用没有扩展名的图片吗? [英] Can I use images without extension in <img>?

查看:80
本文介绍了我可以在< img>中使用没有扩展名的图片吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能存在重复:






我想使用类似于< img src =advertisements / 12style =border:1px固体> 在页面中。 FireFox不会显示它,这让我觉得我必须为文件有一个文件扩展名。我在这里(对于其他浏览器也是这样),或者像FF类型的FF一样?

编辑

我尝试了各种各样的东西,但它仍然无法正常工作。我现在正确地在文件上添加了一个扩展名(例如,Flash的.swf)。我改变了目录等。当我调用 file_exists()时,文件就在那里,所有的开心和这样的,但我绝对不能让它呈现在页。它可以是 img 标记中的.PNG,也可以是Flash对象。两者都不起作用。我做错了什么:-(
另外,如果我将非上传文件重命名为脚本正在查找的文件,那可以正常工作,但上传的文件不会...

解决方案

是的,您应该可以。

浏览器最初不会看它们查看HTTP服务器响应中Content-type头中列出的MIME类型,如果内容类型是image / jpeg,或者是png或者gif或者其他什么,那么事情会很好,并且会很高兴地呈现图像。

如果没有有效的MIME类型,某些浏览器会尝试猜测类型是什么,它们会查看请求对象的扩展名,你会看到前几个字节,如果失败了,你会得到一个redex。



在Firefox / Firebird的早期阶段,这会导致一些问题,因为它对mime类型是严格的,并且经常拒绝呈现没有有效MIME类型的东西。IE做了一个猜测,并且这么多草率的web服务rs会提供可以在IE中渲染的页面,但不会在其他页面渲染。所以,只要你的web服务器在请求img对象时提供正确的MIME类型,你就会很好去。如果您遇到问题,请检查您的网络服务器在请求advertisements / 12时正在做什么。


Possible Duplicate:
Is it safe to serve an image on the web without an extension?

I'd like to use something like <img src="advertisements/12" style="border: 1px solid"> in a page. FireFox won't display it, which makes me think I have to have a file extension for the file. Am I right here (for the other browsers too), or does FF like mime types?

EDIT

I've tried all sorts of stuff and it still won't work. I now put an extension on the file correctly (.swf for Flash, for example). I've changed the directory, etc etc. When I call file_exists(), The file is there, all happy and such, however I absolutely cannot get it to render on the page. It could either be a .PNG in an img tag, or a Flash object. Neither works. What am I doing wrong :-( Also, if I rename a non-uploaded file to the file the script is looking for, that works fine, but the uploaded ones don't...

解决方案

Yes, you should be able to.

Browsers initially don't look at the filename, they look at the MIME type listed in the Content-type header in the response from the HTTP server. If the content type is image/jpeg, or png or gif or whatever, things are good and it will happily render the image.

If there is no valid MIME type, some browsers will try to guess what the type is. They'll look at the extension of object being request, or they'll look at the first few bytes. If that fails, then you get a redex.

That used to cause some woes back in the early days of Firefox / Firebird, because it was strict about mime types and often refused to render something without a valid MIME type. IE made a guess, and so many sloppy web servers would serve up pages that would render fine in IE, but not in others. These days though, things are much better.

So, as long as your web server is providing the right MIME type when the img object is requested, you'll be good to go. If you are having problems, check what your web server is doing when "advertisements/12" is requested.

这篇关于我可以在&lt; img&gt;中使用没有扩展名的图片吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆