Answer the question
In order to leave comments, you need to log in
Can't change file permissions with php chmod?
Can't change file permissions with chmod php
<?php
echo "Current user:".get_current_user()."\r\n";
$processUser = posix_getpwuid(posix_geteuid());
print "Process user:".$processUser['name']."\r\n";
chdir( dirname ( __FILE__ ) );
//$old = umask(0);
$fname='./1.js';
//$fname= dirname ( __FILE__ ).'/1.js';
echo $fname."\r\n";
echo "current perm:".substr(sprintf('%o', fileperms($fname)), -4)."\r\n";
$permitions=fileperms($fname);
chmod($fname,0444);
echo "Try to 444:\r\n";
echo "current perm:".substr(sprintf('%o', fileperms($fname)), -4)."\r\n";
echo "Return:\r\n";
chmod($fname,$permitions);
echo "current perm:".substr(sprintf('%o', fileperms($fname)), -4)."\r\n";
//umask($old);
?>
Answer the question
In order to leave comments, you need to log in
In fact, everything changed.
fileperms cached the previous result.
Inserted clearstatcache(); before fileperms and everything was displayed as expected.
print_r(posix_getpwuid(fileowner($filename)));
Who is the owner of the file? Must be apache, otherwise it will fail
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question