At work, we sometimes encounter operations that require batch processing of files in a certain directory. At this time, we need to find all the qualified files in the directory and save them into a result set, and then facilitate batch processing. Usually The method is to save it into an array and then process it in a loop. The process will be recorded below.
Copy the code The code is as follows:
//php gets all the files in the directory and saves the results To the array
foreach(glob("./*") as $d){
$tmp=explode('.',$d);
$k=end($tmp);
//If it is a file, and the file extension is jpg png
if(is_file($d)&&in_array($k,array('jpg','png'))){
$files[] =$d;
}
}
echo '
';print_r($files);
The above source code lists all the suffixes in the current directory. jpg png file, save the result as an array and then print it out. The results of this test are printed as follows:
http://www.bkjia.com/PHPjc/824871.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/824871.htmlTechArticleAt work, sometimes we encounter the need to batch process files in a certain directory. At this time, we will You need to find all the files that meet the conditions in this directory and save them to a...