2

I want to change the chmod values of the files from the user. But it does not work. My code is;

$chmod = "0777";
chmod($filename, $chmod);

I am entering chmod 777. But the chmod value of the file is 1411. I tried chmod 0777, 777, 00777. The results remain the same.

6
  • 1
    The most common reason this doesn't work is your webserver is running with user and group permissions that don't allow it to change the file. When you log in, it's often with greater permissions than the webserver has. Can you tell us who owns the file (user & group) and what user & group your web server is? Commented Aug 14, 2017 at 18:14
  • Does $filename contains the full path to the file? Does the user has proper permission to change permission on this file? Commented Aug 14, 2017 at 18:14
  • Not totally familiar with this functions but based on the comments on the php docs, you may need to put your mode number (0777) in the function octdec() instead of the quotes. Commented Aug 14, 2017 at 18:17
  • You php running as apache or php user, to be able chmod inside folder, you have to change the owner of this folder or add change permissions for specific user. Example: setfacl -m u:php:rwx myfolder Commented Aug 14, 2017 at 18:17
  • Possible duplicate of php chmod() not changing permissions Commented Aug 14, 2017 at 20:11

2 Answers 2

6
+50

The problem has to do with data conversion.

$chmod = "0777";
chmod($filename, octdec($chmod));

By just passing in the $chmod string it get converted 777 witch is not giving you want. octdec("0777") will output 511 that decimal will give chmod the value you want.

Sign up to request clarification or add additional context in comments.

1 Comment

Yes! Thanks Bro.
0

Check the file path and file name is correct! then try this

chmod("/somedir/somefile", 0755);

1 Comment

It works this way. But I want to change it from the incoming.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.