Welcome! Log In Create A New Profile

Advanced

[PHP] Can't use copy() to copy files

Posted by Ben Stones 
Ben Stones
[PHP] Can't use copy() to copy files
October 14, 2008 07:20PM
Ok, here is my code (mind it is a bit messy I was just testing to see if it
works first of without success):

if($_GET['act'] == "update") {
$check_exists=file_exists($_GET['file']);
if($check_exists==1) {
if(copy($_GET['file'],$_GET['file'])) {
echo 5;
}
else {
echo $_GET['file'];
}
}
}

Obviously it doesn't echo 5, it just echo's the file name which is a sign it
isn't copying. If I change it to: copy($_GET['file'],"Hello/".$_GET['file'])
it copies file, and sure enough I check the directory to find it has copied
too. This code is in a seperate directory and I have changed both that
directory, the Hello directory and the file being copied to 777 permissions
but no luck. I noticed the following in the error_log:

[14-Oct-2008 18:07:38] PHP Warning: copy(/index.php) [<a
href='function.copy'>function.copy</a>]: failed to open stream: Permission
denied in /home/vinat/public_html/Files/test.php on line 31
Any help appreciated!
Jim Lucas
Re: [PHP] Can't use copy() to copy files
October 14, 2008 07:25PM
Ben Stones wrote:
> Ok, here is my code (mind it is a bit messy I was just testing to see if it
> works first of without success):
>
> if($_GET['act'] == "update") {
> $check_exists=file_exists($_GET['file']);
> if($check_exists==1) {
> if(copy($_GET['file'],$_GET['file'])) {
> echo 5;
> }
> else {
> echo $_GET['file'];
> }
> }
> }
>
> Obviously it doesn't echo 5, it just echo's the file name which is a sign it
> isn't copying. If I change it to: copy($_GET['file'],"Hello/".$_GET['file'])
> it copies file, and sure enough I check the directory to find it has copied
> too. This code is in a seperate directory and I have changed both that
> directory, the Hello directory and the file being copied to 777 permissions
> but no luck. I noticed the following in the error_log:
>
> [14-Oct-2008 18:07:38] PHP Warning: copy(/index.php) [<a
> href='function.copy'>function.copy</a>]: failed to open stream: Permission
> denied in /home/vinat/public_html/Files/test.php on line 31
> Any help appreciated!
>

your source and destination are the same. you can't do that. Even windows
cries when you try that.. :)

--
Jim Lucas

"Some men are born to greatness, some achieve greatness,
and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
by William Shakespeare


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Sorry, only registered users may post in this forum.

Click here to login