/*
* 1、获取路径的文件名
* string basename(string path[,string suffix])
path 必需。规定要检查的路径。
suffix 可选。规定文件扩展名。如果文件有 suffix,则不会输出这个扩展名。
eg:
<?php
$path = "/testweb/home.php";
//显示带有文件扩展名的文件名
echo basename($path);
//显示不带有文件扩展名的文件名
echo basename($path,".php");
?>
输出:
home.php
home
* 2、获取路径的目录
* string dirname(string path)
path 必需。规定要检查的路径。
eg:
<?php
echo dirname("c:/testweb/home.php");
echo dirname("/testweb/home.php");
?>
输出:
c:/testweb
/testweb
* 3、了解更多的路径信息
* array pathinfo(string path,string options)
path 必需。规定要检查的路径。
options 可选。规定要返回的数组元素。默认是 all。
可能的值:
PATHINFO_DIRNAME - 只返回 dirname
PATHINFO_BASENAME - 只返回 basename
PATHINFO_EXTENSION - 只返回 extension
说明
pathinfo() 返回一个关联数组包含有 path 的信息。
包括以下的数组元素:
[dirname]
[basename]
[extension]
eg:
<?php
print_r(pathinfo("/testweb/test.txt"));
?>
输出:
Array
(
[dirname] => /testweb
[basename] => test.txt
[extension] => txt
)
* 4、确定绝对路径
* string realpath(string path)
eg:
<?php
echo realpath("test.txt");
?>
输出:
C:\Inetpub\testweb\test.txt
* 5、确定文件的大小
* int filesize(string filename)
eg:
<?php
echo filesize("test.txt");
?>
输出:
20
* 6、计算磁盘的可用空间
* float disk_free_space(string directory)
该函数将根据相应的文件系统或磁盘分区返回可用的字节数
* 7、计算磁盘的总容量
* float disk_total_space(string directory)
该函数将根据相应的文件系统或磁盘分区返回所有的字节数
eg:
<?php
echo disk_total_space("C:");
?>
输出类似这样:
509693888668
* 8、确定文件的最后访问时间
* int fileatime(string filename)
* 9、确定文件的最后改变时间
* int filectime(string filename)
* 10、确定文件的最后修改时间
* int filemtime(string filename)
* 11、识别文件末尾字符
* int feof(string resource)
* 12、打开和关闭文件
* resource fopen(string resource,string mode[,int use_include_path[,resource zountext]])
* boolean fclose(resource filehandle)
* 13、将文件读入数组
* array file9string filename[,int user_inlucde_path[,resource context]])
* 14、将文件内容读入字符串变量
* string file_get_contents(string filename[,int use_inlude_path[resource context]])
* 15、将CSV文件读入数组
* array fgetcsv(resource handle[,int length[,string delimiter[,string enclosure]]])
* 16、读取指定数目的字符
* string fgets(resource handle[,int length])
* 17、从输入中剔除标记,清除所有HTML和PHP标记
* string fgetss(resourcce handle,int length[,string allowable_tags])
* 18、以一次读取一个字符的方式读取文件
* string fgetc(resource handle)
* 19、忽略换行符
* string fread(resource handle,int length)
* 20、读取整个文件
* int readfile(string filename[,int use_include_path])
* 21、根据预定义的格式读取文件
* mixed fscanf(resource handle,string format[,string var1])
* 22、将字符串写入文件
* int fwrite(resource handle,string string[,int length])
* 23、移动文件指针
* int fseek(resource handle,int offset[,int whence])
*
* 1、打开目录句柄
* resource opendir(string path)
* 2、关闭目录句柄
* void closedir(resource directory_handle)
* 3、解析目录内容
* string readdir(resource directory_handle)
* 4、将目录读入数组
* array scandir(string directory[,int sorting_order[,resource context]])
*
*
* 1、删除目录
* int rmdir(string dirname)
* 2、重命名文件
* boolean rename(string olename,string newname)
* 3、触摸文件
* int touch(sting filename[,int time[,int atime]])
*/
PHP文件操作系统
最新推荐文章于 2022-10-27 17:22:04 发布