View Full Version : Reference in 'glob'

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


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.

10-05-2012, 06: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.

10-06-2012, 01: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.

10-06-2012, 03: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.

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