永发信息网

PHP如何获取文件夹下所以子文件夹的名称及子夹所以图片

答案:2  悬赏:80  手机版
解决时间 2021-03-04 05:50
  • 提问者网友:抽煙菂渘情少年
  • 2021-03-03 08:48
PHP如何获取文件夹下所以子文件夹的名称并显示
点击其中名称打开名称文件夹下的所以图片并显示
最佳答案
  • 五星知识达人网友:污到你湿
  • 2021-03-03 09:23
$dir = '你的图片根目录';
function listImages($dir)
{
$images = array();
$entries = glob($dir . '/*');

if(!empty($entries)) foreach($entries as $ent) {
if($ent == '.' || $ent == '..') continue;
if(is_dir($ent)) {
$images = array_merge($images, listImages($ent));
} else if( substr(mime_content_type($ent), 0, 5) == 'image' ) {
$images[] = $ent;
} else {
continue;
}
}

return $images;
}
var_dump(listImages($dir));
全部回答
  • 1楼网友:長槍戰八方
  • 2021-03-03 10:13
先写个函数来遍历文件夹下的所有子文件: function my_scandir($dir) { $files = array(); if ( $handle = opendir($dir) ) { while ( ($file = readdir($handle)) !== false ) { if ( $file !
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯