Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/299.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP OpenDir函数在我的Ubuntu Linux机器上不起作用_Php_Linux_File_Opendir - Fatal编程技术网

PHP OpenDir函数在我的Ubuntu Linux机器上不起作用

PHP OpenDir函数在我的Ubuntu Linux机器上不起作用,php,linux,file,opendir,Php,Linux,File,Opendir,最近,我将我的机器的操作系统从Windows改为Linux,但现在我的PHP应用程序似乎没有在新机器中运行opendir函数。下面是我的代码: public function scandirs($dir){ $listDir = array(); if($handler = @opendir($dir)) { while (($sub = readdir($handler)) !== FALSE) { if ($sub != "."

最近,我将我的机器的操作系统从Windows改为Linux,但现在我的PHP应用程序似乎没有在新机器中运行opendir函数。下面是我的代码:

public function scandirs($dir){

    $listDir = array();

    if($handler = @opendir($dir)) {

        while (($sub = readdir($handler)) !== FALSE) {

            if ($sub != "." && $sub != ".." && $sub != "Thumb.db") {

                if(is_file($dir."/".$sub)) {

                    $listDir[] = $dir.'\\'.$sub;
                }
                elseif(is_dir($dir."/".$sub)){

                    $listDir[$sub] = scandirs($dir."\\".$sub);
                }
            }
        }   

        closedir($handler);
    }

    return $listDir;  
}
如果我执行var_dumpopendir$dir;它只返回一个false

编辑

我需要补充的是,我正在从Linux终端运行文件。

这可能是目录权限问题。检查您试图打开的目录的权限。
当我们将php应用程序从windows切换到Linux环境时,文件权限和文件路径是两个常见的问题。

变量$dir的内容是什么?地址是/var/www/html/esurance365/app/sys/project如果您从命令行终端运行脚本,它将以您的权限执行。终端中ls/var/www/html/esurance365/app/sys/project的输出是什么?project是目录吗?如果其第一个参数不是目录或不允许打开,则失败。删除并让它显示失败的原因。@axiac我已经删除了它,它只返回boolfals。您的错误可能在全局级别被抑制,或者被记录到php_errors.log中。将错误报告放在所有位置;ini_设置“显示错误”,“1”;在脚本之上,您将在屏幕上看到它们。文件权限是完全读取、写入和执行权限您是通过浏览器还是通过cron执行脚本?否,通过Linux终端您登录的用户是否拥有您前面提到的所有权限?