Glob gave me no results

I am trying to use PHP Glob to get a list of files based on a wildcard, namely an extension.

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

I know that there is a file in this directory, namely: 23.png, but it does not appear in the $ images array. I don’t know why not. I tried to make the URL even more absolute (or explicit), for example:

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

No result.

Could it be that Glob is not installed correctly inside PHP? Or is there another reason this does not produce any results?

+7
source share
2 answers

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

http://www.website.com/content/big/ can really be /var/www/site/content/big on the server and that is the path you need to use.

Enabling the path with / makes glob in the root folder for this folder, and I assume that your server does not have a folder named /content/big/ .

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

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

Or use the absolute path:

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

below is my implementation, single quotes do not work with echo, but this works for me. Hope this helps!

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

All Articles