Got it.
PHP Code:
<?php
$str="0755";
echo "$str ";
var_dump(is_int($str));
$str="0755";
$str=intval($str);
echo"<br>$str ";
var_dump(is_int($str));
$str="0755";
$str=intval($str, 8);
echo"<br>$str ";
var_dump(is_int($str));
##chmod("test2.php", intval($str, 8));
?>
produces:
0755 bool(false)
755 bool(true)
493 bool(true)
in php.net it says chmod needs the mode to be in the format of an integer. When passing a value via $_POST this can be a little difficult to do. My guess is that the format is always in a string.
$str="0755"; a string
$str='0755'; a string
$str=0755; a number that is recognized as an octal number. This is not the same as 755. If you echo it you will get 493. I can't use this, because when the number is passed via $_POST I get it in string format. sprint treats the string however you want, but does not convert it. int($str) just converts the string to an integer, but we lose the leading zero. decoct($str) changes dec to oct, but we convert it away from a string in the process.
intval(); will get the integer value of the number as well, but here we run into the same problem where leading zeros are lost. You can, however, specify that you want to preserve the octal format by
intval($str, 8);
base 8 numbering in this case.
I got the hint here.
Bookmarks