-
- //Open the subdirectory common under the directory pic in the current directory.
- $handler = opendir('pic/common');
Copy code
2. Loop to read all files in the directory
-
- /*where $filename = readdir($handler)
- Every During the second loop, the read file name is assigned to $filename, $filename !== false.
- Be sure to use !==, because if a file name is called '0', or something is considered false by the system, using != will stop the loop
- */
- while( ($filename = readdir($ handler)) !== false )
- {
- //Skip files named '.' and '..' in the linux directory
- if($filename != “.” && $filename != “..”)
- {
- //Output file name
- echo $filename;
- }
- }
Copy code
3. Close the directory
Two ,php determines file and directory functions
Code:
-
-
- //Check whether the target object logo.jpg in the upper-level directory is a file.
- $checkResult = is_file(’../logo.jpg’);
Copy code
Description: If the target object is a file, the system returns true, otherwise it returns false.
Code:
-
-
- //Check whether the target object logo.jpg in the upper-level directory is a directory.
- $checkResult = is_dir(’../logo.jpg’);
Copy code
Description: If the target object is a directory system, return true, otherwise return false.
|