当allow_url_fopen=off时PHP图像抓取
我在我的 WordPress 博客上使用论文主题。我在 byethost 托管我的博客,其中有 allow_url_fopen=Off 和 allow_url_include=Off
在其中一个函数中,代码尝试读取图像 url 路径。据我了解,如果fopen为ON,它将执行“if”情况,否则“else”情况
if ($thesis_design->image['fopen'])
$image_path = $post_image['url'];
else {
$local_path = explode($_SERVER['SERVER_NAME'], $post_image['url']);
$image_path = $_SERVER['DOCUMENT_ROOT'] . $local_path[1];
}
使用此代码,如果我提供绝对路径(即 http://brijux.com/images/example.jpg),但它可以使用相对路径抓取图像(即 images/example.jpg)
但是如果我注释掉“if”情况并仅使用“else”情况,它可以使用绝对路径抓取图像。
所以我的问题是,
- 如果allow_url_fopen=Off,它不应该只执行“else”部分吗?
- 如果我只在“if”情况下提供相对路径,它如何抓取图像文件?
I am using thesis theme on my wordpress blog. I am hosting my blog at byethost which has allow_url_fopen=Off and allow_url_include=Off
In one of the function, code is trying to read an image url path. From what I understand, if fopen is ON, it will execute "if" case otherwise "else" case
if ($thesis_design->image['fopen'])
$image_path = $post_image['url'];
else {
$local_path = explode($_SERVER['SERVER_NAME'], $post_image['url']);
$image_path = $_SERVER['DOCUMENT_ROOT'] . $local_path[1];
}
With this code, it is not able to grab the image if I provide absolute path (i.e. http://brijux.com/images/example.jpg) but it can grab image with relative path (i.e images/example.jpg)
But if I comment out "if" case and use only the "else" case, it can grab image with the absolute path.
So my question is,
- if allow_url_fopen=Off, shouldn't it only execute the "else" part?
- how does it grab image file if I am only providing relative path in the "if" case?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您使用 fopen 并提供相对路径,它会将图像视为本地文件。如果您提供“绝对”路径,即 URL,那么它会通过环回接口并像在网络上一样获取它。
If you use fopen and provide a relative path it treats the image as a local file. If you provide the 'absolute' path i.e. the URL then it goes through the loopback interface and grabs it like it's on the web.