glob()不搜索文件夹

时间:2013-03-17 15:13:20

标签: php post glob

我认为我做的事情从根本上说是错误的。这是我的代码

的index.php

<?php

if(isset($_POST['a'])){
    $action = $_POST['a'];
} else if(isset($_GET['a'])){
    $action = $_GET['a'];
} else {
    $action = "home";
}


if($action == "home"){
    $frontImages = glob('assets/images/frontpage/*');
    include_once 'home.php';
}
?>

我在var_dump($frontImages)内部homp.php(btw显示正常)但我得到$frontImages是一个未定义的变量。 index.php文件和home.php文件都在根文件夹中,这是路径目录的图像:

enter image description here

所以不确定我在这里做错了什么。

1 个答案:

答案 0 :(得分:0)

使用

<?php

if(isset($_REQUEST['a'])) {
    $action = $_GET['a'];
} else {
    $action = "home";
}


if($action == "home"){
    while($acImg = glob('assets/images/frontpage/*')) {
        $frontImages[] = $acImg;
    }
    include_once 'home.php';
}
?>

现在你有一个数组,但我的工作原理