Hi guys

I'm having a bit of a problem with php and linux.
I'm using the following function, to find files with specific file extensions within a given folder and all subfolders :

function FindVideoFiles($startfolder,$specificextensions){
        $it = new RecursiveDirectoryIterator($startfolder);
        foreach( new RecursiveIteratorIterator($it) as $file) {
            if (in_array(strtoupper(substr($file, strrpos($file, '.') + 1)), $specificextensions)) {
                $files[]=array('nomedapasta'=>pathinfo($file,PATHINFO_DIRNAME));
            }
        }
        return $files;
}

$specificextensions is an array with 'avi','mkv' and 'mp4' as values.
$startfolder is a string with "/mnt/HD1_4TB/refazer/A View to a Kill" as value.

When i try to run the function, it throws me an error saying "failed to open dir: No such file or directory".
The weirdest thing is, if i change the $starfolder variable to "/mnt/HD1_4TB/refazer", the function works and return the files inside the folder "A View to a Kill" (even with spaces in folder name).
If i rename the folder "A View to a Kill" to "AViewtoaKill" and change the $startfolder variable to "/mnt/HD1_4TB/refazer/AViewtoaKill", the function also work.....
so..... i think that my problem is the spaces in the folder name.
Can someone help me on how i can solve this problem without removing the spaces in folder name ??

Thanks

I see this has been marked as solved. Please add the solution for us to learn with you.

and another question - why you do not use pathinfo($file,PATHINFO_EXTENSION) insead of substr($file, strrpos($file, '.') + 1) in line 4?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.