views:

131

answers:

2

I have a script that is uploading images to my site, it works locally (haven't even tested it on the web server yet) but the problem is that I can't figure out how to get it to upload the images to a central location no matter where the script is run from.

For example my site structure looks like this:

/ROOT/
   /IMAGES/
   /USER/
      upload.php
      /IMAGES/
      /ADS/
         upload.php
         /IMAGES/
      /COUPONS/
         upload.php
         /IMAGES/

Right now the different upload.php files inherit from another php file that has the uploading script. Inside the script the line that sets the upload path looks like this $newname = "images/".$image_name;. That line is why I have an "images" directory under User and one under ADs and one under Coupons. What I want is to be able to have my script upload all images to the /IMAGES/ directory under the /ROOT/ directory, but I can only figure out how to make the path go up levels (using "../") rather than start at the root and go down. How can I get it to always upload to the /ROOT/IMAGES/ directory?

+6  A: 

this should work

$newname = $_SERVER['DOCUMENT_ROOT']."/images/".$image_name;
Tim
+2  A: 

Use:

$path = $_SERVER['DOCUMENT_ROOT'];
$path .= '/images/';
menkes