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

Recently I changed the OS for my machine from Windows to Linux but now my PHP application doesn't seem to run the opendir() function within the new machine. Below is my code:

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;  
}

If I perform a var_dump(opendir($dir)); it just returns a false.

EDIT

I need to add that I am running the files from the Linux Terminal.

It can be directory permission issue. Check the permission of directory which you are trying to open. File permission and File path are two common issues we face when we switch our php application from windows to Linux environment.