CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   PHP (http://www.codingforums.com/forumdisplay.php?f=6)
-   -   Reference in 'glob' (http://www.codingforums.com/showthread.php?t=275331)

keys88 10-05-2012 05:02 PM

Reference in 'glob'
 
How would
PHP Code:

$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:
PHP Code:

$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
 
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.


All times are GMT +1. The time now is 12:39 AM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.