By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,480 Members | 1,146 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,480 IT Pros & Developers. It's quick & easy.

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

P: n/a
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.




Jun 2 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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.
Jun 2 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.