PHP example - PHP writes a function to scan and print out the names of all jpg files in a custom directory (including subdirectories)

微波
Release: 2023-03-11 18:50:01
Original
1354 people have browsed it

下面小编就为大家带来一篇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);
Copy after login

这个函数在我本地运行的时候回超时,可能是我本地图片有点多,好几十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!

Related labels:
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!