PDA

View Full Version : Copy function in PHP



Akalon
September 20th, 2001, 00:37
How come this works:


copy("start/index.pl","whereever/index.pl");


but not this?


copy("start/index.pl","../../whereever/index.pl");


Is there something else I have to do?

Akalon
September 20th, 2001, 03:36
Please somebody!:(

niv
September 20th, 2001, 06:56
Did you try the full path? :confused:

Akalon
September 20th, 2001, 07:30
Yeah, didn't work :(

Akalon
September 20th, 2001, 07:32
You mean like /web/sites/122/digitalvelocity2/www.digital1.f2s.com/locked/data/ or is there another way?

niv
September 20th, 2001, 07:46
Maybe because you don't have the UNIX permissions to write to that folder.

Akalon
September 20th, 2001, 08:25
Nope it's cmodded fine, it actually does copy... but not 2 folders back, it makes the folder inside the folder the script is in.

jm4n
September 20th, 2001, 10:11
First, always use a full path. PHP does chdir() to the current directory I think, but it's still better to use a full path to avoid any problems and narrow down the possibilities.

Second, is your PHP running in safe_mode? Do you have an open_basedir set? Do a phpinfo() and see if either of these values is set.

If you're on a shared server, most likely you have an open_basedir set to your directory, to avoid reading/writing to someone else's files.

Regarding permissions, remember that (assuming PHP is run as an Apache module) PHP runs as the webserver user -- so you must make sure any directories/files to be modified by PHP are writable by that user. If the webserver user is not in your group, then this means you must make them world-writable.

Finally, if in safe_mode, PHP will not touch a file you don't own, period.

You should check the return value of the copy function, and check your error logs. PHP always gives useful information; you might turn error_reporting up a notch or two to make sure you will see the error messages. This will tell you exactly what the problem is.