php 文件file常用的操作

多是代码形式呈现,更多的信息可以查看php api文档,搜索Filesystem;

//创建文件夹

$path_find = AppRoot . '/Temp/excel_curl'; //查找的路径
if ( !file_exists( $path_find ) ) {
    mkdir( $path_find, 0777, true );
}

//创建文件

可以直接用file_put_contents,此函数会判断是否存在文件,不存在则创建.

//删除文件

unlink();

//删除目录

rmdir();

//判断文件夹下有无文件

1  if ( $handle = opendir( $path_find ) ) {       
2         while ( false !== ($file = readdir( $handle )) ) {
3             if ( $file != '.' && $file != '..' ) {
4              //你想做的操作
5               .........
6     }        
原文地址:https://www.cnblogs.com/sheapchen/p/3214313.html