Page 1 of 1

[SOLVED] copy(): I can't get the paths right!

Posted: Thu Sep 08, 2005 9:07 am
by Skittlewidth
Hi,

I've been trying to move a file from one folder on a web server to another using copy.

If I use chdir() on the folder the image file is in before calling the function I can sucessfully copy the file within the same folder but with a different name:

Code: Select all

chdir("images");
//from the webroot this folder is contribute/static/images/
copy("image.jpg", "newimage.jpg");
I can even move it into the next folder up in the hierachy by doing:

Code: Select all

chdir("images");
copy("image.jpg", "../newimage.jpg");
But then it gets too complicated... I need to move the file to another folder which is two folders down from the webroot: (htdocs) so I tried "assets/images/newimage.jpg" but the folder could not be found because this path is not relative to the "images" folder chdir is set to.

So then I tried "../../../assets/images/newimage.jpg" which is the three levels up out of one folder to the root and back down two levels into the other. I've tried many combinations but I either get "no such file or directory" or "basedir restriction in effect...."

The example in the manual only copies and renames a file into the same directory as the source so I got no help here. Can I chdir() mid function to send the file to the correct destination?

Posted: Thu Sep 08, 2005 9:14 am
by feyd
if you know the location of the destination relative to the document root you can use $_SERVER['DOCUMENT_ROOT'] quite often ;)

Posted: Thu Sep 08, 2005 9:19 am
by Skittlewidth
of course!

Cheers feyd, a quick chmod of the destination folder on top of that (I'd forgotten about permissions too) and it all worked fine. Thanks for the reminder! 8)