如何用PHP遍历文件夹获取所有图片文件?
- 内容介绍
- 文章标签
- 相关推荐
本文共计189个文字,预计阅读时间需要1分钟。
header('Content-Type:text/; charset=gbk');if (!empty($_GET['parent_id'])) { $id1=M('goods_category')->where('id=' . $_GET['id'])->find();} elseif (!empty($_GET['id'])) { $id1=M('goods_category')->where('parent_id=' . $_GET['id'])->find();}
header('content-type:text/html;charset=gbk');
if(!empty($_GET['parent_id'])){
$id1 = M('goods_category')->where('id='.$_GET['id'])->find();
}elseif(!empty($_GET['id'])){
$id1 = M('goods_category')->where('parent_id='.$_GET['id'])->find();
}else{
$id1 = M('goods_category')->where('parent_id=1')->find();
}
if(!empty($id1['cat_group'])){
$hostdir = './public/images/'.$id1['cat_group'].'/';
$url = "./public/images/".$id1['cat_group'].'/';
$filesnames = scandir($hostdir); //得到所有的文件
$count = count($filesnames)-2;
$www = 'localhost/'; //域名
$aurl = array();
foreach ($filesnames as $k => $name) {
if($name == '.' || $name == ".."){
unset($name);
}else{
$aurl[$k]['img']= iconv('gbk','utf-8',$www.$url.$name); //图片
}
}
}else{
$aurl = '';
}
本文共计189个文字,预计阅读时间需要1分钟。
header('Content-Type:text/; charset=gbk');if (!empty($_GET['parent_id'])) { $id1=M('goods_category')->where('id=' . $_GET['id'])->find();} elseif (!empty($_GET['id'])) { $id1=M('goods_category')->where('parent_id=' . $_GET['id'])->find();}
header('content-type:text/html;charset=gbk');
if(!empty($_GET['parent_id'])){
$id1 = M('goods_category')->where('id='.$_GET['id'])->find();
}elseif(!empty($_GET['id'])){
$id1 = M('goods_category')->where('parent_id='.$_GET['id'])->find();
}else{
$id1 = M('goods_category')->where('parent_id=1')->find();
}
if(!empty($id1['cat_group'])){
$hostdir = './public/images/'.$id1['cat_group'].'/';
$url = "./public/images/".$id1['cat_group'].'/';
$filesnames = scandir($hostdir); //得到所有的文件
$count = count($filesnames)-2;
$www = 'localhost/'; //域名
$aurl = array();
foreach ($filesnames as $k => $name) {
if($name == '.' || $name == ".."){
unset($name);
}else{
$aurl[$k]['img']= iconv('gbk','utf-8',$www.$url.$name); //图片
}
}
}else{
$aurl = '';
}

