开发者

PHP upload image to one directory from multiple pages

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 loo开发者_如何学运维ks 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?


this should work

$newname = $_SERVER['DOCUMENT_ROOT']."/images/".$image_name;


Use:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜