why can't PHP chmod a file that is already 777?

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I've a simple script to transfer some files from one domain to
another, with both domains living on the same server. The files in
both directories are already chmod 777. Yet after transfer, I try to
ensure that the file is 777, and I get an error. Why?

for ($i=0; $i < count($transferArray); $i++) {
    $fileName = $transferArray[$i];
    $commandAsString = "\cp -f /var/www/vhosts/mydomain.com/httpdocs/
site_specific_files/$fileName /var/www/vhosts/theice.org/httpdocs/
$fileName", 0777);
    if ($i > 0) $resultString .= ", ";
    $resultString .=  "$fileName";

The files copy over just fine, but the line where I try to do chmod, I
get this error:

"Warning: chmod(): Operation not permitted in /var/www/vhosts/
transferFilesFromCyberbittenToTSR.php on line 33"

The owner and the group of the file change to "www-data" which is
annoying, but which should allow PHP to do anything it wants with the
files. So why would I get an error?

I also tried to end with this line:

exec("chown mgtr /var/www/vhosts/ice.org/httpdocs/site_specific_files/

This doesn't work at all. Why?

I ssh to the server and edited the configuration files to be sure the
open_basedir restriction was off,  then I rebooted Apache. That made
no difference, for this particular bug.

Re: why can't PHP chmod a file that is already 777?

lawrence k wrote:
Quoted text here. Click to load it

I haven't seen your entire command, but cp could be failing here. a+x on
the destination directory.. chown won't change the owner unless the
person running it is root or through sudo.

Site Timeline