public static function set_readable($filename, $readable = true)
    {
        $stat = @stat($filename);

        if ($stat === false) {
            return false;
        }

        // We're on Windows
        if (strncasecmp(PHP_OS, 'WIN', 3) === 0) {
            return true;
        }

        list($myuid, $mygid) = array(posix_geteuid(), posix_getgid());

        if ($readable) {
            // Set only the user readable bit (file is owned by us)
            if ($stat['uid'] == $myuid) {
                return chmod($filename, fileperms($filename) | 0400);
            }

            // Set only the group readable bit (file group is the same as us)
            if ($stat['gid'] == $mygid) {
                return chmod($filename, fileperms($filename) | 0440);
            }

            // Set the world readable bit (file isn't owned or grouped by us)
            return chmod($filename, fileperms($filename) | 0444);
        } else {
            // Set only the user readable bit (file is owned by us)
            if ($stat['uid'] == $myuid) {
                return chmod($filename, (fileperms($filename) | 0444) ^ 0444);
            }

            // Set only the group readable bit (file group is the same as us)
            if ($stat['gid'] == $mygid) {
                return chmod($filename, (fileperms($filename) | 0444) ^ 0044);
            }

            // Set the world readable bit (file isn't owned or grouped by us)
            return chmod($filename, (fileperms($filename) | 0444) ^ 0004);
        }
    }
public static function set_readable($filename, $readable = true)
    {
        $stat = @stat($filename);

        if ($stat === false) {
            return false;
        }

        // We're on Windows
        if (strncasecmp(PHP_OS, 'WIN', 3) === 0) {
            return true;
        }

        list($myuid, $mygid) = array(posix_geteuid(), posix_getgid());

        if ($readable) {
            // Set only the user readable bit (file is owned by us)
            if ($stat['uid'] == $myuid) {
                return chmod($filename, fileperms($filename) | 0400);
            }

            // Set only the group readable bit (file group is the same as us)
            if ($stat['gid'] == $mygid) {
                return chmod($filename, fileperms($filename) | 0440);
            }

            // Set the world readable bit (file isn't owned or grouped by us)
            return chmod($filename, fileperms($filename) | 0444);
        } else {
            // Set only the user readable bit (file is owned by us)
            if ($stat['uid'] == $myuid) {
                return chmod($filename, (fileperms($filename) | 0444) ^ 0444);
            }

            // Set only the group readable bit (file group is the same as us)
            if ($stat['gid'] == $mygid) {
                return chmod($filename, (fileperms($filename) | 0444) ^ 0044);
            }

            // Set the world readable bit (file isn't owned or grouped by us)
            return chmod($filename, (fileperms($filename) | 0444) ^ 0004);
        }
    }
public static function set_readable ( $ filename , $ readable = true ) { $ stat = @ stat ( $ filename ) ; if ( $ stat === false ) { return false ; } // We're on Windows if ( strncasecmp ( PHP_OS , 'WIN' , 3 ) === 0 ) { return true ; } list ( $ myuid , $ mygid ) = array ( posix_geteuid ( ) , posix_getgid ( ) ) ; if ( $ readable ) { // Set only the user readable bit (file is owned by us) if ( $ stat [ 'uid' ] == $ myuid ) { return chmod ( $ filename , fileperms ( $ filename ) | 0400 ) ; } // Set only the group readable bit (file group is the same as us) if ( $ stat [ 'gid' ] == $ mygid ) { return chmod ( $ filename , fileperms ( $ filename ) | 0440 ) ; } // Set the world readable bit (file isn't owned or grouped by us) return chmod ( $ filename , fileperms ( $ filename ) | 0444 ) ; } else { // Set only the user readable bit (file is owned by us) if ( $ stat [ 'uid' ] == $ myuid ) { return chmod ( $ filename , ( fileperms ( $ filename ) | 0444 ) ^ 0444 ) ; } // Set only the group readable bit (file group is the same as us) if ( $ stat [ 'gid' ] == $ mygid ) { return chmod ( $ filename , ( fileperms ( $ filename ) | 0444 ) ^ 0044 ) ; } // Set the world readable bit (file isn't owned or grouped by us) return chmod ( $ filename , ( fileperms ( $ filename ) | 0444 ) ^ 0004 ) ; } }
Set the readable bit on a file to the minimum value that allows the user
running PHP to read to it.

@param  string  $filename The filename to set the readable bit on
@param  boolean $readable Whether to make the file readable or not
@return boolean
Set the readable bit on a file to the minimum value that allows the user running PHP to read to it .