PHP 文件函数

来源:互联网 发布:java反射调用单例 编辑:程序博客网 时间:2024/04/30 19:56
 From: http://hi.baidu.com/kakuma/blog/item/940e911ea4fd9e1c413417d2.html

1、int     filesize(string filename),获取文件的大小。对于2~4GB之间的文件,可以使用sprintf("%u",filesize($file))来处理

2、bool     unlink(string filename) ,删除一个文件

3、bool     rmdir(string dirname)      ,删除一个目录

4、bool     mkdir(string     pathname [,int     mode])      ,新建一个由lpathname指定的目录,mode是指操作权限,默认为0777,表示最大可能的访问权限

5、string basename(string path [,string suffix]) ,path参数给出一个文件的全路径字符串,函数返回基本的文件名。如文件名以suffix结束,则去掉这部分

6、string     dirname(string path) ,返回路径中的目录部分。

7、array     pathinfo(string path) ,返回文件路径的信息,包含以下的数组单元dirname,basename,extension.

8、string     realpath(string path)     ,返回规范化的绝对路径名

9、bool    copy( string     source     ,string dest) ,将文件从source复制到dest

                        例:copy("hello.txt","temp.php");

10、float    disk_free_space(string    directory )    ,返回目录中的可用空间

                        例:$df = disk_free_space("F:/");
                               echo $df.'<br>';

11、float    disk_total_space(string    directory) ,获取指定磁盘总空间

                         例:$df=disk_total_space("F:/");
                                echo $df.'<br>';

12、int    file_put_contents(string filename,string data[,int flags[,resource context]]),将一个字符串写入文件

13、string    file_get_contents(string filename [,int use_include_path[,resource context]]) ,将整个文件作为一个字符串读入。不需要之前fopen()

                         例:$lines=file_get_contents("hello.txt");
                                echo nl2br($lines);

14、int    fileatime(string filename) ,取得文件的上次访问时间

                          例:echo    date("F d Y    H:i:s",fileatime($filename);

15 、int filemtime(string filename),取得文件的最近修改时间

                          例:echo    date("F d Y    H:i:s",filemtime($filename);

16、array   stat( string filename)   给出文件的信息   or   lstat( string filename)   or   fstat( resource handle)

                          例: $fileinfo =stat($filename);
                                 echo "<table border=1><th>数字下标</th><th>关键(自PHP 5.1.4)</th>";
                                 foreach($fileinfo as $num=>$info)
                                 {
                                       echo "<tr><td>".$num."</td><td>".$info."</td></tr>";
                                 }
                                 echo "</table>";

17、string   filetype(string   filename) ,获取文件的类型

                           例:echo filetype($filename);

18、bool   is_dir(string   filename) ,判断给定文件名是否是一个目录

                           例:if(is_dir($filename))
                                           echo $filename.'为目录<br>';
                                 else
                                           echo $filename.'非目录<br>';

19、bool   flock(int handle,int   operation [,int &wouldblock])   ,进行文件锁定

                              operation: LOCK_SH:共享锁定

                                             LOCK_EX: 独占锁定

                                             LOCK_UN: 释放锁定

20、bool   is_uploaded_file(string   filename)   ,判断文件是否通过HTTP POST上传

21、bool   move_uploaded_file(string filename,string   destination)   检测文件是否是合法的上传文件,是则移动到destination 指定的文件