SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Evangelist Fleeters's Avatar
    Join Date
    Jul 2003
    Location
    Dumpsville
    Posts
    406
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Storing Image Location in a Variable, for a CMS.

    hey,

    I am confused working with uploading images, and how to set a variable that stores where the images will be uploaded.

    The CMS will have a setup page where you enter all your information(root dir of the CMS and where Images for your site will be uploaded too.)..

    what I have been doing is setting a variable, then the value that the user enters is added to $_SERVER['DOCUMENT_ROOT'], like this:
    PHP Code:
    $image_location $_SERVER['DOCUMENT_ROOT'] . "/images"
    then whenever an image is uploaded, it is uploaded to that directory.

    I guess what confuses me is if i were to put this on another system. would that not work?? I am just confused about how you have to reference directories in scripts. because I have not made a CMS that was going to be portable before...

    anyone got any suggestions.
    Aaron Smith
    smithaaronlee.net

  2. #2
    Ceci n'est pas Zoef Zoef's Avatar
    Join Date
    Nov 2002
    Location
    Malta
    Posts
    1,111
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Have a look at these:
    PHP Code:
    // The directory of this file (might be an include):
    $dir dirname(__FILE__);
    // the directory of the script ('or 'motherfile' if you like)
    $dir dirname($_SERVER['PATH_TRANSLATED']); 
    The first returns the directory of the file this line is in.

    The second is probably what you are after, it returns the directory the script is running in, even if this line is part of an included file (the included file being in another directory)

    Rik
    English tea - Italian coffee - Maltese wine - Belgian beer - French Cognac

  3. #3
    get into it! bigduke's Avatar
    Join Date
    May 2004
    Location
    Australia
    Posts
    847
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Since your root folder in this case can be changed this would work just fine as long as you don't want the image directory to be different. However if you wish to have a changable image directory, a relative path naming scheme such as the following would work.
    PHP Code:
    $image_dir $_SERVER['DOCUMENT_ROOT']."/".$CMS_VARS['images']; 
    where $CMS_VARS is a custom variable and $CMS_VARS['images'] stores the name of the image directory under the current directory.


Bookmarks

Posting Permissions

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