My code is like
$perm = "0777"; //this is fetch from the database
chmod("myFolder/", $perm);
but the value of $perm is not in octal, how can I change the data type of the variable to octal? even an alternative method will do
My code is like
$perm = "0777"; //this is fetch from the database
chmod("myFolder/", $perm);
but the value of $perm is not in octal, how can I change the data type of the variable to octal? even an alternative method will do
Octal is not a type. Integer is the type.
You want to convert a string to an int, and because of that the string starts with a zero, it will be an octal integer.
Use intval for this:
I needed to feed the mode component of
chmod()
as a variable inside a function. I spent sufficient time trying (and failing) to convert the string into an octal while maintaining the 0777 value. In the end, I decided to abandonchmod()
/ftp_chmod()
and opted forftp_site()
which doesn't choke on string-type mode codes.This worked for me. If this is somehow flawed or not best practice, please explain.
Edit: Some readers may reject this ftp_ solution as cheating because it is not a filesystem function solution. It was a non-issue for me because I was writing a function in a ftp class.
Nothing seemed to work for me so i just created a very stupid solution and I'm just gonna post it here.
As it was mentioned, there is no octal number type. And chmod function receive the second param as integer number. Implicit conversion of
$perm
does not assume that number is octal. So, you need convert your "octal string" to integer by using appropriate function.Just use octdec function
Or intval
P.S.