Home >Backend Development >PHP Tutorial >Development process and example sharing of php file directory operations
We often encounter operations such as generating file directories and editing files (folders). Today I will introduce to you a file directory operation class in PHP, which can create directories, delete directories, create files, delete files, move folders, and copy Folders and a series of functions you can operate.
First download the file directory operation library in PHP that we need to use in this course: http://www.php.cn/xiazai/leiku/544
Find after the download is complete Unzip the php class file we need to our local directory and create a new php file!
After completion, we need to call this class in the new php file and instantiate the class:
<?php include_once "caozuo1.php"; //引入类文件 $obj = new FileUtil; //实例化类 $obj->createDir('a/1/2/3'); //测试建立文件夹 建一个a/1/2/3文件夹 $obj->createFile('b/1/2/3'); //测试建立文件 在b/1/2/文件夹下面建一个3文件 $obj->createFile('b/1/2/3.exe'); //测试建立文件 在b/1/2/文件夹下面建一个3.exe文件 $obj->copyDir('b','d/e'); //测试复制文件夹 建立一个d/e文件夹,把b文件夹下的内容复制进去 $obj->copyFile('b/1/2/3.exe','b/b/3.exe'); //测试复制文件 建立一个b/b文件夹,并把b/1/2文件夹中的3.exe文件复制进去 $obj->moveDir('a/','b/c'); //测试移动文件夹 建立一个b/c文件夹,并把a文件夹下的内容移动进去,并删除a文件夹 $obj->moveFile('b/1/2/3.exe','b/d/3.exe'); //测试移动文件 建立一个b/d文件夹,并把b/1/2中的3.exe移动进去 $obj->unlinkFile('b/d/3.exe'); //测试删除文件 删除b/d/3.exe文件 $obj->unlinkDir('d'); //测试删除文件夹 删除d文件夹 ?>
Note: The result page display of this run will be Blank:
##But in our local I can find the file directory All have been created, as shown below:
##
The above is the detailed content of Development process and example sharing of php file directory operations. For more information, please follow other related articles on the PHP Chinese website!