This article mainly introduces php file operations, including deleting a specified file, obtaining the file name under a folder, and reading the folder name. it involves common php operations on files and directories, for more information about php file operations, see the examples in this article. We will share this with you for your reference. The details are as follows:
1. delete an object
Unlink ()
Syntax: int unlink (string filename );
Return value: integer
Function type: file access. For example:
unlink("tmp/test.txt");
2. get the file name under the folder
$ Dir = "message/"; // folder name if (is_dir ($ dir) {if ($ dh = opendir ($ dir )) {while ($ file = readdir ($ dh ))! = False) {echo "file name: $ file
";}Closedir ($ dh );}}
3. read the image name under the folder
<? Php $ handle = opendir ('images/'); // the current directory while (false! ==( $ File = readdir ($ handle) {// traverse the list ($ filesname, $ kzm) of the directory where the php file is located = explode (". ", $ file); // Obtain the extension if ($ kzm =" gif "or $ kzm =" jpg "or $ kzm =" JPG ") {// File Filter if (! Is_dir ('. /'. $ file) {// folder filter $ array [] = $ file; // Save the qualified file name to the array $ I ++; // record the total number of images }}print_r ($ array);?>