Link to home
Start Free TrialLog in
Avatar of error77
error77

asked on

PHP Copy Function issue with file permissions

Hi all,

I am using to copy function to copy a file from one place to the other.

It works well but the problem is that the copied file cannot be deleted as it says permision denied.

Does anyone know how to fix this please?

THanks
Avatar of Marco Gasi
Marco Gasi
Flag of Spain image

Hi error77. Are you sure files to delete and their directory have permission 0777?
Avatar of error77
error77

ASKER

Well, the file that's copied is 777 on source but 644 when copied by the copy function :o/
Sorry, I'll try to be more clear: you asked for deleting files, but the folder where these files are in does have permissions set to 0777? Not files it self, but the directory itself?

And about what you said, ensure the destination directory, not only files, have permissions 0777.

Cheers
SOLUTION
Avatar of Keith Brown
Keith Brown
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of error77

ASKER

The Folder is created using mkdir and contains cmod 755 (for some reason it won't let me change it.)

So, yes, it's a permission issue. I just want to control these permissions?

Make sense?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of error77

ASKER

Also, I still cannot delete these folder :o/
I'm not sure which method you're using to copy the file, but the GNU cp command does have the ability to preserve permissions. Here is a quote from the cp manpage


-p     same as --preserve=mode,ownership,timestamps
--preserve[=ATTR_LIST]
              preserve the specified attributes (default: mode,ownership,timestamps), if possible additional  attributes: context, links, xattr, all

So, using "cp -p originalfilename targetfilename" should help.
Also, I should note that you should use the the exec() or or shell_exec() if you use this method.

<?php
echo exec('cp -p originalfilename targetfilename');
?>

Open in new window