We will use several functions to traverse the file names in the directory and display them. One is the opendir directory reading function, and then use readdir to obtain the directory information into an array and then traverse it through while.
Show all files in the directory
The code is as follows
|
Copy code
|
||||
代码如下 | 复制代码 | ||||
|
$array_file = array();
Delete all files in the specified directoryThe code is as follows | Copy code |
/** * Delete all files in the specified directory * * @param String $dir The path to operate * Suitable for range, only used when there are no subfolders in the folder * Source DZ * Organized by Xiaojia (www.bKjia.c0m) on 2006-06-26 */ function dir_clear($dir) { $directory = dir($dir); //Create a dir class (said so in the PHP manual of bKjia.c0m) to read every file in the directory While($entry = $directory->read()) { //Loop through each file and get the file name $entry $filename = $dir.'/'.$entry; //Get the complete file name, with path If(is_file($filename)) { //If it is a file, delete it @unlink($filename); } } $directory->close(); $directory->close(); //Close the class that reads the directory file result(); } http://www.bkjia.com/PHPjc/633115.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/633115.htmlTechArticleTraverse the file names in the directory and display several functions we will use. One is the opendir directory reading function, and then Use readdir to obtain directory information into an array and then traverse it through while. ... |