PHP读取文件目录下所有图片:
方法一:
$path = 'xxxxx'; ///当前目录 $handle = opendir($path); //当前目录 while (false !== ($file = readdir($handle))) { //遍历该php文件所在目录 list($filesname,$kzm)=explode(".",$file); //获取扩展名 if($kzm=="gif" or $kzm=="jpg" or $kzm=="JPG") { //文件过滤 if (!is_dir('./'.$file)) { //文件夹过滤 $array[]=$file;//把符合条件的文件名存入数组 } } }
方法二:
$handle = opendir('D:/'); if(!$handle){ die("error open dir"); } while (false !== ($file = readdir($handle))) { if(fnmatch('*.jpg', $file)){ echo "$file\n"; } } for ( ; false !== ($file = readdir($handle)); ) { if(fnmatch('*.jpg', $file)){ echo "$file\n"; } }
方法三:
<?php $dir = "./images/"; //要获取的目录 echo "**** 获取目录下所有文件和文件夹 ****<hr/>"; //先判断指定的路径是不是一个文件夹 if (is_dir($dir)){ if ($dh = opendir($dir)){ while (($file = readdir($dh))!= false){ //文件名的全路径 包含文件名 $filePath = $dir.$file; echo "<img src='".$filePath."'/>"; } closedir($dh); } } ?>
相关导航:
http://www.savh.cn/thread-135.htm
转载请注明:Savh.Cn 发表