Muhammad Umar
Muhammad Umar

Reputation: 11782

Remove filepaths from an assosiative array in php

I am trying to get all files in a folder. The files are images along with one extra file named as "Thumbs.db"

fOLLowing is my code

$path = $ringPaths[$i];
        $dirname =   substr( $path ,0, -4 );
        $lastpart = basename( $dirname , ".zip");
        $abspath = substr( $dirname ,strpos( $dirname, "com/")+4 );
        $direcotypath = "../".$abspath."/".$lastpart;

        $files = glob($direcotypath."/*.*");
        foreach ($files as $key => &$value) 
        {
                $value = str_replace( "..", $url, $value);
            }

            $final = array_merge($final,$files);

I have tried removing Thumbs.db using following code

foreach ($final as $key => &$value) 
    {     

              if($value == "Thumbs.db")
              {
                unset($final[$key]); 
              }
        }

Anyone know what is wrong with above code? I am still in learning process

Upvotes: 0

Views: 50

Answers (1)

Marty
Marty

Reputation: 39456

Reading the documentation for glob more closely, you will see that you can set flags to filter the type of files that will be returned.

You can try something like:

$files = glob($direcotypath . "/*.{jpg,jpeg,gif,png,bmp}", GLOB_BRACE);
//                                 ^^^ Add more allowed extensions here.

Upvotes: 1

Related Questions