简体   繁体   English

Glob没有给我任何结果

[英]Glob not giving me any results

I'm trying to use PHP's Glob to get a list of files based on a wildcard, namely the extension. 我正在尝试使用PHP的Glob来获取基于通配符的文件列表,即扩展名。

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

I know there is a file in this directory, namely: 23.png but it doesn't show in array $images. 我知道这个目录中有一个文件,即:23.png但它没有在数组$ images中显示。 I don't have a clue why not. 我不知道为什么不。 I've tried making the URL even more absolute (or explicit) like: 我已经尝试使URL更加绝对(或显式),如:

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

Without result. 没有结果。

Could it be that Glob isn't installed properly inside PHP? 可能是因为在PHP中没有正确安装Glob? Or is there another reason this doesn't give any results? 还是有另一个原因,这没有给出任何结果?

glob only works with paths on the server's file system, not URLs. glob仅适用于服务器文件系统上的路径,而不适用于URL。

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. http://www.website.com/content/big/在服务器上可能真的是/var/www/site/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. 使用/在某个路径中查找路径会查找该文件夹的根目录,我假设您的服务器上没有名为/content/big/文件夹。

Try it like this (using a relative path from the server root): 像这样试试(使用服务器根目录的相对路径):

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

Or use an absolute path: 或者使用绝对路径:

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

below is my implementation, single quotes did not work with the echo, but this works for me. 下面是我的实现,单引号不适用于echo,但这对我有用。 Hope it helps! 希望能帮助到你!

            <ul>
                    <?php
                            foreach(glob('audio/*.mp3') as $audio){ echo "<li><a>$audio</a></li>";}
                    ?>
            </ul>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM