Click to See Complete Forum and Search --> : copy() Permission denied error


solomon
12-08-2005, 07:41 AM
I'm trying to write a little script that creates backups of my many mysql databases. Everythings going fine but I'm at a little stumbling point - hopefully someone can help.

The way I am trying to do it is to create backup files by first copying a blank text file which already resides on the server using...
copy($file_to_copy , $name_of_copy);
...and then I intend to stuff the backup information into that duplicated, uniquely named backup file.
The problem I'm getting is ...

Warning: copy(mailinglist08Dec05132559.csv): failed to open stream: Permission denied

...regardless of how I chmod the source file. The script can 'see' the source file OK (I've noticed if I inte...ntionally mistype the source file I get different errors).

For completion, here's my simple copy function:
function f_CreateBackupFile($file_to_copy , $name_of_copy){
// CREATE A COPY OF THE BACKUP FILE AND NAME IT ACCORDINGLY
if (is_file($file_to_copy)){
if (copy($file_to_copy , $name_of_copy)) {
f_narrate("Created new file " . $name_of_copy , 6);
} else {
f_narrate("Failed to copy file " . $file_to_copy , 6);
}
} // END COPY BACKUP FILE LOOP

}


Thanks all!

NogDog
12-08-2005, 08:06 AM
First thing I'd check is the permissions on the directory to which you want to copy the file. The PHP user needs to have read/write/execute permission on that directory (as well as read/execute on that directory's parent directories).

nudave04
12-08-2005, 08:18 AM
What is happening is that php doesn't have permission to write to the destination directory. I'm assuming you (like me) are on a shared host, where php is run as a different user, and you don't have the ability to change the permissions for php globally.

There are two ways around this.

The first is to create a directory with 777 permissions so that php can write to it. This is fine if you are going to manually download the file shortly thereafter and then delete it. But, if you plan on leaving this file in place, this is not a very safe solution.

The second is to use php's built-in ftp functions to connect to "localhost" as yourself (logging in with your user name and password), and then putting the file in the directory you want.

Hope one of these works for you!

solomon
12-08-2005, 08:26 AM
You are both brilliant!

I was copying the blank file into the same root dir - now I've created a chmod777 backup subdirectory and it works just peachy!

Thanks :D I'd have been poking at that for hours!

ausgezeichnete
02-22-2008, 04:39 AM
hii guys i have the same problem on my server
every time i upload images i got this permission denied error and i have did 777
but some pages work properly and others no
inspite they r copying to the same folder????????

iota
02-22-2008, 11:47 PM
Did u set full path like :

/home/user/john/images

Ricardo Araos
07-23-2009, 05:46 PM
Well, I've runned into the same problem and I found that to give full permissions (777) is only the first step in the way to go. In my situation, after giving full access, I kept on with no success so I found that printing the real error, with print_r(error_get_last()) gave me the following info:

Array ( [type] => 2 [message] => move_uploaded_file() [function.move-uploaded-file]: SAFE MODE Restriction in effect. The script whose uid is 613 is not allowed to access /home/sites/mysite/www/myapp/excelFiles owned by uid 533 [file] => /home/sites/mysite/www/myapp/fileLoader.php [line] => 190 )

The solution was to do a chown to fileLoader.php so it would belong to the user with uid 533 instead of 613.