tatty27
tatty27

Reputation: 1554

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

Upvotes: 0

Views: 4922

Answers (2)

glob returns an array type.

Change your code like this

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

Upvotes: 2

TiMESPLiNTER
TiMESPLiNTER

Reputation: 5899

From the PHP doc about glob():

Returns an array containing the matched files/directories, an empty array if no file matched or FALSE on error.

You have to loop over the result

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

Upvotes: 2

Related Questions