There is a certain form in which digital values ​​like "777", "644", etc. are written. then the value of this form is sent by javascript to the php script and passed to the chmod function, but the following syntax will be valid for this function:

chmod($name, 0777); 

and the value for the function is transmitted in the form of three digits, and not four:

 $name = $_POST['name']; $chm = $_POST['chm']; // 777 например chmod($name, $chm); 

how to make from 777 0777? I tried different types of options:

 $cmd = '0'.$cmd; 

but the rights to the file were set completely different, maybe there is a solution on js, like adding zero to the number from the form before sending

  • Are you sure that you have access to the command shell? In the overwhelming majority, the mode of access to a file or directory can only be changed by its owner . - Deonis

2 answers 2

Your problem is that you apparently don’t know or have forgotten that file permissions are set in an octal SI.

UPD: Examples of number conversions in JS and PHP.

js:

 var n = parseInt(document.getElementById('own_input_number'),8); 

php:

 $chmod = decoct($_POST['chm']); 
  • so also tried, both on javascript and php - shol

Yes, the access parameter passed to the function by the second parameter is nothing more than a number in the octal number system (and not in the hex number , as @evlanoff asserts):

 <?php chmod("/somedir/somefile", 755); // десятичное, неверный способ chmod("/somedir/somefile", "u+rwx,go+rx"); // строка, неверный способ chmod("/somedir/somefile", 0755); // восьмеричное, верный способ ?> 

This, so bad ...

  $cmd = '0'.$cmd; 

Here read about it in more detail here .

  • I know this, and I ask how to get 0755 out of 755, for example, only a decimal number is taken from the form - shol
  • Then see this function [** mathematical conversion function **] [1]: [1]: php.su/functions/?decoct - Salivan
  • I tried, from 777 using this function 0777 not to get - shol