Home > Backend Development > PHP Tutorial > php get all file names in directory

php get all file names in directory

巴扎黑
Release: 2016-11-12 14:47:10
Original
1964 people have browsed it

php gets all the file names in the directory
1. First open the directory to be operated and point a variable to it
//Open the subdirectory common under the directory pic in the current directory.
$handler = opendir('pic/common');
2. Loop to read all files in the directory
/* Among them, $filename = readdir($handler) is the file name assignment that will be read each time in the loop. Give $filename, in order not to get stuck in an infinite loop, so $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 )
{
3. There will be two files in the directory, named '.' and '..', do not operate them
if($filename != "." && $filename != ""

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template