Glob没有给我任何结果 [英] Glob not giving me any results

查看:121
本文介绍了Glob没有给我任何结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用PHP的Glob获取基于通配符(即扩展名)的文件列表.

I'm trying to use PHP's Glob to get a list of files based on a wildcard, namely the extension.

$images = glob('/content/big/'.$item['id'].'.{jpg,jpeg,png,gif}', GLOB_BRACE);

我知道此目录中有一个文件,即:23.png,但它不在数组$ images中显示.我不知道为什么不这样做.我尝试过使URL更加绝对(或更明确),例如:

I know there is a file in this directory, namely: 23.png but it doesn't show in array $images. I don't have a clue why not. I've tried making the URL even more absolute (or explicit) like:

$images = glob('http://www.website.com/content/big/'.$item['id'].'.{jpg,jpeg,png,gif}', GLOB_BRACE);

没有结果.

是否可能是Glob在PHP中未正确安装?还是有其他原因没有给出任何结果?

Could it be that Glob isn't installed properly inside PHP? Or is there another reason this doesn't give any results?

推荐答案

glob仅适用于服务器文件系统上的路径,不适用于URL.

glob only works with paths on the server's file system, not URLs.

http://www.website.com/content/big/可能实际上是服务器上的/var/www/site/content/big,这是您需要使用的路径.

http://www.website.com/content/big/ may really be /var/www/site/content/big on the server, and that's the path you need to use.

/标记路径会使glob在该文件夹的根目录中看起来,我假设服务器上没有名为/content/big/的文件夹.

Staring a path with a / makes glob look in your root for that folder, and I'm assuming there is no folder called /content/big/ on your server.

尝试这样(使用来自服务器根目录的相对路径):

Try it like this (using a relative path from the server root):

$images = glob('content/big/'.$item['id'].'.{jpg,jpeg,png,gif}', GLOB_BRACE);

或使用绝对路径:

$images = glob('/var/www/site/content/big/'.$item['id'].'.{jpg,jpeg,png,gif}', GLOB_BRACE);

这篇关于Glob没有给我任何结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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