Here is my code:
function myChmod($path, $permission, $log)
{
//this is to overcome umask limitations that mkdir adheres to
$result = chmod($path, octdec($permission));
if(!$result) {
$log->log("Error failed to chmod '$path' to '$permission'. Exiting.");
throw new Exception("Error failed to chmod '$path' to '$permission'. Exiting.");
}
return $result;
}
$trml2pdfPath = $c->install_path.'assets/trml2pdf/trml2pdf/trml2pdf.py';
myChmod($trml2pdfPath, 0755, $log);
How do I prevent PHP from changing this base-8 number 0755 to base-10 number 493? I wanna use the chmod function in PHP, but it just keeps changing it to 493.
PHP’s chmod() function takes an integer as second parameter. It does not matter whether you pass octal(0755) or dec(493), it’s the same number.
myChmod($trml2pdfPath, 0755, $log);the 0755 here is a number literal. PHP interprets it as the number oct(755)=dec(493), meaning: you don’t need any conversion function in
myChmod().