Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Aug 2010
    Posts
    57
    Thanks
    26
    Thanked 0 Times in 0 Posts

    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.
    Last edited by keys88; 10-05-2012 at 05:09 PM. Reason: minor typo

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    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.

  • #3
    New Coder
    Join Date
    Aug 2010
    Posts
    57
    Thanks
    26
    Thanked 0 Times in 0 Posts

    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.

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    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.

  • Users who have thanked Fou-Lu for this post:

    keys88 (10-06-2012)

  • #5
    New Coder
    Join Date
    Aug 2010
    Posts
    57
    Thanks
    26
    Thanked 0 Times in 0 Posts
    Thank you. Very helpful.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •