This is a discussion on why can't PHP chmod a file that is already 777? within the PHP Language forums, part of the PHP Programming Forums category; I've a simple script to transfer some files from one domain to another, with both domains living on the ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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/ site_specific_files/$fileName"; exec($commandAsString); chmod("/var/www/vhosts/ice.org/httpdocs/site_specific_files/ $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/ cyberbitten.com/httpdocs/sharedCode/ 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/ $fileName"); 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. |
|
|||
|
lawrence k wrote:
> 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/ > site_specific_files/$fileName"; > exec($commandAsString); > chmod("/var/www/vhosts/ice.org/httpdocs/site_specific_files/ > $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/ > cyberbitten.com/httpdocs/sharedCode/ > 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/ > $fileName"); > > 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. 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. |
![]() |
| Thread Tools | |
| Display Modes | |
|
|