php文件相关函数介绍

1 获取路径的文件名

   string basename(string path [, string suffix]);
2 获取路径的目录
     string dirname(string path);
3 了解更多路径信息
     array pathinfo(string path);//可以得到目录信息、文件名和文件扩展名
4 确定文件大小
     int filesize(string filename);//其实filename应该理解是路径,以字节为单位返回值
5 计算磁盘的可用空间
     float disk_free_space(string directory);//计算目录所在磁盘的可用空间
6 计算磁盘的总容量
     float disk_total_space(string directory);//同上
7 计算目录的总大小
     php中没有直接提供这样的函数,但是我们可以自己编写递归函数完成这个功能。
8 确定文件的最后访问时间
     int fileatime(string filename);// 它返回的是UNIX时间戳的形式,可以date("m-d-y g:i:sa", filetime($path));
9 确定文件的最后改变时间
     int filectime(string filename);
10 确定文件的最后修改时间
     int filemtime(string filename);
/*最后修改时间特指对文件内容的修改,而最后改变时间可以是任何形式的改变,如权限、所有者信息等等*/
举例:
$path = "/home/www/data/users.txt";
basename($path);//得到users.txt
basename($path, ".txt");//得到users
$pathinfo = pathinfo($path);
$pathinfo[dirname];//文件目录
$pathinfo[basename];//文件名字
$pathinfo[extension];//文件扩展名 txt
$bytes = filesize($path);
11 识别文件末尾字符
     int feof(string resource);
12 resource fopen(string resource, string mode [, int use_include_path [, resource zcontext]] )

13 关闭文件
     boolean fclose(resource filehandle);
14 将文件读入数组
     array file(string filename[int use include [, resource context]]);
15 将文件内容读入字符串变量
     string file_get_contents(string filename [, int use_include_path [resource context]]);
16 将CVS文件读入数组
     array fgetcsv(resource handle [, int length [, string delimiter [, string enclosure]]]);
17 读取指定书目的字符
     string fgets(resource handle [, int length])
18 从输入中剔除标记
     string fgetss(resource handle, int length [, string allowable_tags])
19 以一次读取一个字符的方式读取文件
     string fgetc(resource handle);
20 忽略换行符从指定资源中读取length个字符
     string fread(resource handle, int length);
21 读取整个文件
     int readfile(string filename [, int use_include_path]);
22 根据预定义的格式读取文件
     mixed fscanf(resource handle, string format [, string var1]);
23 将字符串写入文件
     int fwrite(resource handle, string string [, int length]);
24 将文件指针移到偏移量的指定位置
     int fseek(resource handle, int offset [, int whence]);
25 获取当前指针的偏移量
     int ftell(resource handle);
26 将文件指针移回至文件开始处
     int rewind(resource handle)
27 关闭目录句柄
     void closedir(resource directory_handle)
28 解析目录内容
     string readdir(int directory_handle)
29 将目录读入数组
     array scandir(string directory [, int sorting_order [, resource context]]);     
posted @ 2012-03-19 22:11  cloud_fish  阅读(227)  评论(0编辑  收藏  举报