This article introduces an example code that uses PHP to list all files in a directory for your reference. List all files in the directory, the code is as follows: "; while(false !== ($file=readdir($dir))){ if($file != "." && $file != ".."){ echo "
Copy after login
If the directory and the website are in the same partition, you can also use $current_dir='/temp/'; directly. The above is an example under Windows. Let’s look at a PHP example under Linux that lists all files in a directory. as follows: 1. Get the files in the directory, excluding subdirectories. "; } ?>
Copy after login
2. Get all files in the directory, including subdirectories. read()){ if($file !="." && $file !=".."){ get_allfiles($path."/".$file, $files); } } $dp ->close(); } if(is_file($path)){ $files[] = $path; } } //edit bbs.it-home.org function get_filenamesbydir($dir){ $files = array(); get_allfiles($dir,$files); return $files; } $filenames = get_filenamesbydir("static/image/"); //打印所有文件名,包括路径 foreach ($filenames as $value) { echo $value."
Copy after login
|