I am trying to empty the content of a directory using glob() and foreach() using
$files = glob('/upload/'.$id.'/temp/*.JPEG');
foreach($file as $files){
unlink($file);}
But I just keep getting ‘Invalid argument supplied for foreach()’
Is this just a syntax error or can I not use unlink() in a foreach loop?
Also, just out of curiosity, will this code find all files in a directory?
$files = glob('/upload/'.$id.'/temp/*.*');
Invalid argument supplied for foreach()means the argument you passed is not an array. Here you passed$file.$fileis not array. In fact it does not exists yet.The format of foreach is,
From your code the correct solution would be