6

Here is something i dont understand:

A file has the permission 0644 which if i use php´s fileperms() functions returns 16804 as integer if i make a var_dump(). What/where is the relation between the two and how can i convert a, lets say 0755, into whatever fileperms() would return for 0755.

THX

set*

setcookie
  • 579
  • 1
  • 6
  • 12

1 Answers1

7

16804 is the decimal notation for the octal number 40644. Check 2nd example of the PHP manual for the meaning of these values.

40644 extracted:

  • 4 - the file is a directory
  • 0 - padding to get the first 4 on the 5th position
  • 6 - read-writable for the owner
  • 4 - readable only for the group
  • 4 - readable only for the world.

PHP recognizes numbers with a leading zero as an octal number. If you need to convert a string containing 0755 or 755 to a decimal number, use octdec(). The reverse function (decimal to octal) is decoct().

If you need to change the file permissions of a file, use chmod(). For that to work, you need to be the owner of the file, otherwise you get a Permission denied error.

tim
  • 2,530
  • 3
  • 26
  • 45
Lekensteyn
  • 64,486
  • 22
  • 159
  • 192
  • excellent ... i get it. the first index of the octal value is a little bit confusing. if 4 = directory what is a file then? i didnt find anything while searching the web. – setcookie Oct 25 '11 at 15:26
  • According to the PHP example, a regular file is `0x8000` (octal: 0100000) – Lekensteyn Oct 25 '11 at 15:41