Search code examples
phpsyntax-errordirectory

Warning: file_exists() expects parameter 1 to be string, array given


I tring to check if a folder is empty but I keep getting this error

Warning: file_exists() expects parameter 1 to be string, array given

if(!file_exists(glob('/upload/'.$id.'/temp/*'))){
$smeg = 'empty';
}

Solution

  • glob returns an array type.

    Change your code like this

    foreach(glob('/upload/'.$id.'/temp/*') as $filename)
    {
        if(!file_exists($filename))
        {
           $smeg = 'empty';
        }
    }