通过 PHP 提供的图像不会在 Shadowbox 中加载
我在我的网站上使用 Shadowbox 已经有一段时间了,没有出现任何问题。我创建了一个 PHP 文件来提供受保护文件夹中的媒体内容。以下是 download.php 中的内容:
<?php
$fullpath="/home/user/media/image1.jpg";
header("Content-Type: image/jpeg");
header('Content-Transfer-Encoding: binary');
header('Content-Disposition: inline; filename='.basename($filename));
header("Content-Length: " . filesize($fullpath));
readfile($fullpath);
exit;
?>
如果我使用 IMG 标签调用它或尝试下载图像,效果会很好。例如:
<img src="download.php?id=123" />
但是,如果我使用 Shadowbox,浏览器会变暗,我什至没有加载动画并且没有任何显示。
<a href="download.php?id=358" rel="shadowbox[test]"><img src="download.php?id=358"/></a>
在上面的示例中,图像将显示良好,但单击时不会加载阴影框。
提前致谢!
I've been using shadowbox without issue on my sites without issue for a while now. I've created a PHP file to serve media content from a protected folder. Here is what is in the download.php:
<?php
$fullpath="/home/user/media/image1.jpg";
header("Content-Type: image/jpeg");
header('Content-Transfer-Encoding: binary');
header('Content-Disposition: inline; filename='.basename($filename));
header("Content-Length: " . filesize($fullpath));
readfile($fullpath);
exit;
?>
This works well if I call it using an IMG tag or try and download the image. For example:
<img src="download.php?id=123" />
However, if I use shadowbox the browser darkens and I don't even get a loading animation and nothing displays.
<a href="download.php?id=358" rel="shadowbox[test]"><img src="download.php?id=358"/></a>
The image will display fine with the example above, but the shadowbox won't load when clicked.
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于您的情况,问题是 Shadowbox 在获取内容之前检查文件扩展名。如果您在 Shadowbox.js 中搜索(尝试搜索 img.ext),您会在某处找到它:
img.ext=["bmp","gif","jpg","jpeg","png"]因此
,您可以尝试添加 PHP 来稍微放松一下,Shadowbox 会很高兴地抓取您的图像:
img.ext=["bmp","gif","jpg","jpeg","png","php"];
或者,您可以将 php 文件保存为 jpg (听起来很奇怪,不是吗?)并强制服务器将其作为 php 文件进行处理。例如,如果您使用 Apache 并且允许
.htaccess
,您可以尝试创建.htaccess
(或将这些行添加到现有的.htaccess
文件中) 和:The problem—for your case—is, Shadowbox check for file extension before fetching the content. If you search inside shadowbox.js (try search for img.ext), you will find this somewhere:
img.ext=["bmp","gif","jpg","jpeg","png"];
So, you could try adding PHP to loosen it a bit and Shadowbox will happily grab your image:
img.ext=["bmp","gif","jpg","jpeg","png","php"];
Or, you could save your php file as jpg (sounds weird, no?) and force the server to process it as a php file. For example, if you use Apache and
.htaccess
is allowed, you could try creating.htaccess
(or adding these line to existing.htaccess
file) with:在 htaccess 级别对图像打开 php 不会带来巨大的安全风险吗?
Wouldn't turning php on on images at the htaccess level be a huge security risk?