现在的位置: 首页 > 综合 > 正文

php文件操作(类型和属性)

2012年03月14日 ⁄ 综合 ⁄ 共 3186字 ⁄ 字号 评论关闭
  1. 文件类型

     1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     2  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     3 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
     4 <head> 
     5  <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
     6  <title>文件类型</title>
     7 </head>
     8 <body>
     9 <?php
    10 $linux_file_type = array(
    11     array(
    12         'type' => 'block',
    13         'des' => '块设备文件,如某个磁盘分区、软驱、光驱CD-ROM等'
    14     ),
    15     array(
    16         'type' => 'char',
    17         'des' => '字符设备是指在I/O传输过程中以字符为单位进行传输的设备,例如键盘,打印机等'
    18     ),
    19     array(
    20         'type' => 'dir',
    21         'des' => '目录类型'
    22     ),
    23     array(
    24         'type' => 'fifo',
    25         'des' => '命名管道,常用于将信息从一个进程传输到另一个进程'
    26     ),
    27     array(
    28         'type' => 'file',
    29         'des' => '普通文件类型,如文本文件或可执行文件等'
    30     ),
    31     array(
    32         'type' => 'link',
    33         'des' => '符号链接,是指向文件指针的指针,类似Windows中的快捷方式'
    34     ),
    35     array(
    36         'type' => 'unknown',
    37         'des' => '未知类型'
    38     )
    39 );
    40 
    41 $windows_file_type = array(
    42     $linux_file_type[2],
    43     $linux_file_type[4],
    44     $linux_file_type[6]
    45 );
    46 
    47 ?>
    48 <table border="1" cellspacing="0" cellpadding="0">
    49     <caption>linux文件类型</caption>
    50     <tr>
    51         <th>文件类型</th>
    52         <th>描述</th>
    53     </tr>
    54     <?php foreach($linux_file_type as $file_type){
    55         echo "<tr><td>{$file_type['type']}</td><td>{$file_type['des']}</td></tr>";
    56     }?>
    57 </table>
    58 <br/>
    59 <table border="1" cellspacing="0" cellpadding="0">
    60     <caption>windows文件类型</caption>
    61     <tr>
    62         <th>文件类型</th>
    63         <th>描述</th>
    64     </tr>
    65     <?php foreach($windows_file_type as $file_type){
    66         echo "<tr><td>{$file_type['type']}</td><td>{$file_type['des']}</td></tr>";
    67     }?>
    68 </table>
    69 
    70 <ul>
    71     <li>在PHP中使用 filetype() 函数获取文件的上述类型,它接受一个文件名为参数,若文件不存在返回FALSE</li>
    72     <li>对于一个已知文件可以用 is_file()函数判断给定的文件名是否为一个文件,类似的,使用is_dir()函数判断给定的文件名是否是一个目录</li>
    73 </ul>
    74 </body>
    75 </html>
  2. 文件属性

     1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     2  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     3 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
     4 <head> 
     5  <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
     6  <title>文件属性</title>
     7 </head>
     8 <body>
     9 <?php
    10 $file_property_func = array(
    11     array(
    12         'name' => 'file_exists()',
    13         'todo' => '检查文件或目录是否存在',
    14         'param' => '文件名',
    15         'return' => '文件存在返回TRUE,不存在返回FALSE'
    16     ),
    17     array(
    18         'name' => 'filesize()',
    19         'todo' => '获取文件大小',
    20         'param' => '文件名',
    21         'return' => '返回文件大小的字节数,出错返回FALSE'
    22     ),
    23     array(
    24         'name' => 'file_readable()',
    25         'todo' => '判断给定文件名是否可读',
    26         'param' => '文件名',
    27         'return' => '若文件存在且可读返回TRUE'
    28     ),
    29     array(
    30         'name' => 'file_writable()',
    31         'todo' => '判断给定文件名是否可写',
    32         'param' => '文件名',
    33         'return' => '若文件存在且可写返回TRUE'
    34     ),
    35     array(
    36         'name' => 'file_executable()',
    37         'todo' => '判断给定文件名是否可执行',
    38         'param' => '文件名',
    39         'return' => '若文件存在且可执行返回TRUE'
    40     ),
    41     array(
    42         'name' => 'filectime()',
    43         'todo' => '获取文件的创建时间',
    44         'param' => '文件名',
    45         'return' => '返回UNIX时间戳格式'
    46     ),
    47     array(
    48         'name' => 'filemtime()',
    49         'todo' => '获取文件的修改时间',
    50         'param' => '文件名',
    51         'return' => '返回UNIX时间戳格式'
    52     ),
    53     array(
    54         'name' => 'fileatime()',
    55         'todo' => '获取文件的访问时间',
    56         'param' => '文件名',
    57         'return' => '返回UNIX时间戳格式'
    58     ),
    59     array(
    60         'name' => 'stat()',
    61         'todo' => '获取文件大部分属性值',
    62         'param' => '文件名',
    63         'return' => '返回关于给定文件有用信息的数组'
    64     )
    65 );
    66 ?>
    67 <table border="1" cellspacing="0" cellpadding="0">
    68     <caption>PHP的文件属性处理函数</caption>
    69     <tr>
    70         <th>函数名</th>
    71         <th>作用</th>
    72         <th>参数</th>
    73         <th>返回值</th>
    74     </tr>
    75     <?php foreach($file_property_func as $func){
    76         echo "<tr><td>{$func['name']}</td><td>{$func['todo']}</td><td>{$func['param']}</td><td>{$func['return']}</td></tr>";
    77     }?>
    78 </table>
    79 </body>
    80 </html>

     

抱歉!评论已关闭.