Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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);

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);

Without result.

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
697 views
Welcome To Ask or Share your Answers For Others

1 Answer

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

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.

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);

Or use an absolute path:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...