当allow_url_fopen=off时PHP图像抓取

发布于 2024-09-28 21:02:28 字数 827 浏览 2 评论 0原文

我在我的 WordPress 博客上使用论文主题。我在 byethost 托管我的博客,其中有 allow_url_fopen=Offallow_url_include=Off

在其中一个函数中,代码尝试读取图像 url 路径。据我了解,如果fopenON,它将执行“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”情况,它可以使用绝对路径抓取图像。

所以我的问题是,

  1. 如果allow_url_fopen=Off,它不应该只执行“else”部分吗?
  2. 如果我只在“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,

  1. if allow_url_fopen=Off, shouldn't it only execute the "else" part?
  2. how does it grab image file if I am only providing relative path in the "if" case?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小霸王臭丫头 2024-10-05 21:02:28

如果您使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文