English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

PHP 基礎教程

PHP 高級教程

PHP & MySQL

PHP 参考手冊

PHP fileperms() 関数の用法及び例

PHP Filesystem 参考手冊

fileperms()関数はファイルやディレクトリの権限を返します。この関数は成功時に数字形式で権限を、失敗時にfalseを返します。

文法

int fileperms ( string $filename )

例1

<?php
   echo substr(sprintf("%o", fileperms("sample.txt")), -4);
?>

出力結果

0666

例2

<?php
   $perms = fileperms("sample.txt");
   switch($perms & 0xF000) {
      case 0xC000: // ソケット
         $info = 's';
         break;
      case 0xA000: // シンボリックリンク
         $info = 'l';
         break;
      case 0x8000: // レギュラ
         $info = 'r';
         break;
      case 0x6000: // ブロックスペシャル
         $info = 'b';
         break;
      case 0x4000: // ディレクトリ
         $info = 'd';
         break;
      case 0x2000: // キャラクタースペシャル
         $info = 'c';
         break;
      case 0x1000: // FIFO pipe
         $info = 'p';
         break;
      デフォルト: // unknown
         $info = 'u';
   }
   // オーナー
   $info .= (($perms & 0x0100) ? 'r' : ''-);
   $info .= (($perms & 0x0080) ? 'w' : ''-);
   $info .= (($perms & 0x0040) ?
            ((($perms & 0x0800) ? 's' : 'x' ) :
            ((($perms & 0x0800) ? 'S' : ''-);
   // グループ
   $info .= (($perms & 0x0020) ? 'r' : ''-);
   $info .= (($perms & 0x0010) ? 'w' : ''-);
   $info .= (($perms & 0x0008) ?
            ((($perms & 0x0400) ? 's' : 'x' ) :
            ((($perms & 0x0400) ? 'S' : ''-);
   echo $info;
?>
テストを見て‹/›

出力結果

rrw-rw-

PHP Filesystem 参考手冊