PHP链接到根文件夹之外的图像[a href,而不是img src]
这是我的情况:图像存储在根文件夹之外。我可以使用外部 php 文件(应该如此)访问它们,然后 file_get_contents
然后 echo
然后 img src
它然后它会完美显示。
我安装了厚盒,我想要发生的是当用户单击图像时,它将在放大的厚盒中显示
<a href="img.jpg" class="thickbox"><img src="my_image_processing.php?img=img.jpg" />
我正在尝试在单击时创建一个图库。发生的情况是厚盒显示但图像没有显示。乱码/垃圾代码不是显示图像,而是带有带问号的黑色菱形。我想这是图像的原始代码。
我如何将其输出为图像而不是
<a href> 's
添加中的原始代码:我只是多玩了一下。当我删除thickbox类时,a href
实际上起作用了。它通常在下一页上显示图像。不幸的是,当我附加厚盒类时,它显示了厚盒,但它显示了原始代码
Here's my situation: Images are stored outside root folder. I can access them with an external php file (as it should be) then file_get_contents
then echo
then img src
it then it will show perfectly.
I have thickbox installed and what I want to happen is when a user clicks on the image, it will show in the thickbox enlarged
<a href="img.jpg" class="thickbox"><img src="my_image_processing.php?img=img.jpg" />
I'm trying to create a gallery upon clicking. What happens is the thickbox shows up but the image doesn't. Instead of the image, the gibberish/garbage codes show up with black diamonds with a questionmark. I suppose this is the raw code of the image.
How can I output that as image and not raw code in
<a href> 's
ADDED: I just played around with it a bit more. When I remove the thickbox class, the a href
actually works. It displays the image normally on the next page. Unforunately when I attach the thickbox classes, it shows the thickbox, but it shows the raw code
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
尝试:
如果您将原始图像数据视为文本,则您的浏览器可能无法将输出识别为图像。您可以使用上面的标题行来表示正确的 mime 类型。
也有可能发生错误并且错误消息使图像文件不可读(因为流以错误消息开头而不是标头)。在这种情况下,您应该在字符之前看到错误消息。
Try:
If you see the raw image data as text, probably your browser does not recognize the output as an image. You can signal the right mime type with the header line above.
It is also possible that an error occures and error messages make the image file unreadable (because instead of the headers the stream starts with an error message). In that case you should see the error message before the characters.
在您的示例中,您直接使用 jpg 文件,它应该类似于:
即读取隐藏文件夹并返回图像的 php 页面。
In your example you are using the jpg file directly, it should be something like:
That is, the php page that read the hidden folder and return the image.
Thickbox 识别由文件扩展名链接的资源类型,以确定它是否是要显示的图像。在确定扩展名时,它还会忽略查询字符串。因此,您有以下选择:
my_image_processing/img.jpg
这样的 URL 而不是my_image_processing.php?img=img.jpg
(搜索有关“mod_rewrite”的更多信息),一件事是让 Thickbox 认为它加载图像,而不是加载到框架中的页面,第二件事是 - 正如 vbence 指出的 - 将正确的 mime 类型添加到您随脚本返回的图像中:您应该添加带有“Content-Type”信息的适当标头。
编辑:
负责显示图像的代码开始如下[原文如此!]:
如果您选择自己修改脚本,您可能希望添加另一种类型('php'),但您应该注意的后果。
EDIT2:
如果您选择“更改插件”选项,还有一些替代方案(ColorBox),这使您无需深入代码即可决定 *.php 链接是否应被视为图像。只需在文档中查找
photo
选项(当设置photo= true
应该如您所期望的那样运行)。Thickbox recognizes the type of the resource linked by the file extension to determine, whether it is an image to be displayed, or not. It also ignores the query string when determining extension. Thus, you have the following options:
my_image_processing/img.jpg
instead ofmy_image_processing.php?img=img.jpg
(search for more info on "mod_rewrite"),One thing is making Thickbox think it loads image, not a page into the frame, and the second one is - as vbence pointed - adding proper mime type to the image you return with your script: you should add appropriate header with "Content-Type" information.
EDIT:
The code responsible for displaying images begins as follows [sic!]:
You may wish to add another type ('php'), if you choose to modify the script yourself, but you should be aware of the consequences.
EDIT2:
If you go with the 'change plugin' option, there is some alternative (ColorBox), that makes you able to decide without the need to dig into the code, whether the *.php link should be treated as image. Just look for the
photo
option within the documentation (when setphoto=true
should behave as you would expect).您可能忽略了用于显示图像的 http 标头。
You've probably neglected the http headers for displaying an image.