Error in using glob function with wordpress

2

I am trying to recover images from a folder with the native function of php glob , but it is returning an empty array . I'm passing the complete path of the folder to the function.

Follow the code below:

$pasta = get_template_directory_uri() . '/img/projetos/' . get_post_meta($post->ID, 'projeto', true) .'/';              
$imagens = glob("$pasta{*jpg,*png}", GLOB_BRACE) or die ("Erro ao acessar $pasta");
    
asked by anonymous 18.03.2014 / 05:06

2 answers

2

You are passing a URL ( glob " is expecting a Path / Path (# : //codex.wordpress.org/Function_Reference/get_template_directory "title=" Codex documentation ">

18.03.2014 / 11:58
0

First of all, make sure your path $ folder is valid "need to end with / "

Then use this:

$a = glob($pasta.'*.{jpg,png}',GLOB_BRACE);
echo '<pre>';
print_r($a);
    
18.03.2014 / 09:19