Stanley Ngumo
Stanley Ngumo

Reputation: 4239

PHP OpenDir function doesnt work on my Ubuntu Linux machine

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.

Upvotes: 0

Views: 748

Answers (1)

Vishal
Vishal

Reputation: 742

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.

Upvotes: 0

Related Questions