Home > Article > Backend Development > PHP example - PHP writes a function to scan and print out the names of all jpg files in a custom directory (including subdirectories)
下面小编就为大家带来一篇php写一个函数,实现扫描并打印出自定目录下(含子目录)所有jpg文件名。
写一个PHP函数,实现扫描并打印出自定目录下(含子目录)的所有jpg文件名的方法
<?php
$dir = "E:\照片\\";
//打印文件夹中所有jpg文件
function printJpg($dir,$deep = ""){
$dirSource = dir($dir);
while($d = $dirSource->read()){
if($d == "." || $d == ".."){
continue;
}
if(filetype($dir.$d) == "dir"){
printJpg($dir.$d."/",$deep."--");
}
if(mime_content_type($dir.$d) == "image/jpeg"){
echo $deep.$d."<br/>";
}
}
}
printJpg($dir);这个函数在我本地运行的时候回超时,可能是我本地图片有点多,好几十G图片。
The above is the detailed content of PHP example - PHP writes a function to scan and print out the names of all jpg files in a custom directory (including subdirectories). For more information, please follow other related articles on the PHP Chinese website!