...

View Full Version : Reference in 'glob'



keys88
10-05-2012, 05:02 PM
How would


$list=glob('{../pics/*.jpg,*JPG,*jpeg}',GLOB_BRACE);

need to be written with $_SERVER['DOCUMENT_ROOT'] in place of the relative reference?

I can't figure out those nested quote marks.

Thank you.

Fou-Lu
10-05-2012, 05:30 PM
Not sure what you mean about the nested quote marks.
Try this:


$list = glob($_SERVER['DOCUMENT_ROOT'] . '/pics/*.{jpg,JPG,jpeg}', GLOB_BRACE);

Personally I wouldn't use DOCUMENT_ROOT whenever I can avoid it; I'd use explicit relative to this file's directory.

keys88
10-06-2012, 12:51 AM
Thank you.

I see I also had the open-brace in the wrong place.

I will use the relative reference.

For general knowledge: what's the drawback of using DOCUMENT_ROOT?

I thought it had the advantage of letting files be moved without changing the references.

Fou-Lu
10-06-2012, 02:53 AM
DOCUMENT_ROOT itself isn't the problem, its $_SERVER. PHP cannot guarantee anything under the $_SERVER superglobal as existing, and if you use PHP on the command line or cron jobs, than this superglobal offset isn't available.

keys88
10-06-2012, 08:04 PM
Thank you. Very helpful.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum