TechniqueUse the fileperms() function to accurately get the number value of the permissions, or use the is_* ( is_dir() , is_executable() , is_file() , is_link() , is_readable() , and is_writable() ) functions to get human-usable results. Using fileperms() : <?php if ((fileperms ($fn) & 0777) != 0644) { chmod ($fn, 0644); // rw-r--r- } ?> Using the is_* functions: <?php if (!is_readable ($fn)) { chmod ($fn, 0777); // rwxrwxrwx } ?> CommentsThe fileperms() function returns the current permissions numerically (in octal form). This is a more advanced way of checking the file permissions. The bits making up the permissions returned by fileperms() are described in more detail in the man page for the mknod() function in UNIX. If you simply want to check whether the file is available for read access, write access, and so on, use the is_* functions. Please be aware that these functions are costly on the system, and therefore they are cached. To make multiple calls on the same file, you need to use the clearstatcache() function. For more information see recipe 6.7. |