Forum Moderators: coopster

Message Too Old, No Replies

copying files

php copy function probs

         

huds

7:05 pm on Dec 3, 2005 (gmt 0)

10+ Year Member



Hope someone can help with this, i am stumped.

The situation is I have a template.php file, and I wan't my script to copy this file and give the new copy a new name.

This is the code so far, but it doesn't copy...

$temp = "template.php";
$file = $linktextdata . ".php";

if (!copy($temp, $file)) {
echo "copy of $temp failed";
}

I test echoed the variables, and they look ok.

Any ideas?

dmorison

7:14 pm on Dec 3, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This is almost certainly down to the file access permissions that PHP has in the directory that you are trying to write to.

What you need to do is:

a) Find out what user PHP is running as on your server, then

b) Make sure that user has write permission in the directory

If you're on Linux, you can test to see if this is the problem by quickly giving everybody write access to the directory (do something like chmod a+w dirname). If that does the trick, then look up how to manage group permissions on Linux and make the user apache a member of a group that has write access to the directory you want to use.