开发者

Running glob() from an included script returns empty array

开发者 https://www.devze.com 2023-03-24 14:50 出处:网络
Perhaps I\'m over-looking some minor error somewhere, however I have spent 20 minutes staring at this and re-reading the PHP manual, which is far too long for me to spend on a single line of code.

Perhaps I'm over-looking some minor error somewhere, however I have spent 20 minutes staring at this and re-reading the PHP manual, which is far too long for me to spend on a single line of code.

I am writing a WordPress plugin which is imp开发者_如何学JAVAlemented as a class. In my plugin I have the following line:

$choices = glob(dirname(__FILE__)."/images/*.{gif,jpg,jpeg,png}", GLOB_BRACE);

Clearly I want $choices to be an array containing every image in the "images" folder, relative to the included file. The line originally looked like this:

$choices = glob("images/*.{gif,jpg,jpeg,png}", GLOB_BRACE);

However it was returning an array with several images from an entirely different folder (the wp-admin/images folder, to be specific). My best bet is that it's because the function which calls glob() was itself called by the admin_init hook, which is called by a script in the wp-admin folder. In order to make the search relative to my plugin and not the wp-admin folder I applied the dirname(__FILE__) at the beginning.

My issue now is that I'm getting an empty array. I even tried:

var_dump(dirname(__FILE__)."/images/*.{gif,jpg,jpeg,png}");

to see exactly what was getting passed. The following was returned:

string(79) "/home/coupon/public_html/wp-content/plugins/DE-menu/images/*.{gif,jpg,jpeg,png}"

Which looks just fine to me... As I said, perhaps I'm over-looking something simple. Anyone have any ideas?


Please add the images to your folder!

0

精彩评论

暂无评论...
验证码 换一张
取 消