JBZoo\Utils\FS::writable PHP Method

writable() public static method

Set the writable bit on a file to the minimum value that allows the user running PHP to write to it.
public static writable ( string $filename, boolean $writable = true ) : boolean
$filename string The filename to set the writable bit on
$writable boolean Whether to make the file writable or not
return boolean
    public static function writable($filename, $writable = true)
    {
        return self::_setPerms($filename, $writable, 2);
    }

Usage Example

コード例 #1
0
ファイル: FileSystemTest.php プロジェクト: jbzoo/utils
 public function testWritable()
 {
     if (Sys::isWin()) {
         //skip('This functionality is not working on Windows.');
         return false;
     }
     if (Sys::isRoot()) {
         skip('These tests don\'t work when run as root');
     }
     isFalse(FS::writable('/no/such/file'));
     // Create a file to test with
     $dirname = dirname(__FILE__);
     $file = $dirname . '/test7';
     touch($file);
     chmod($file, 0644);
     // The file is owned by us so it should be writable
     isTrue(is_writable($file));
     is('-rw-r--r--', FS::perms($file));
     // Toggle writable bit off for us
     FS::writable($file, false);
     clearstatcache();
     isFalse(is_writable($file));
     is('-r--r--r--', FS::perms($file));
     // Toggle writable bit back on for us
     FS::writable($file, true);
     clearstatcache();
     isTrue(is_writable($file));
     is('-rw-r--r--', FS::perms($file));
     unlink($file);
 }