I have folder, his name is “1”, in this folder is 2 folders: “big_images” and “small_images”
I want delete folder “1” and his content, this is code:
function removeFullDir ($dir) {
$content = glob($dir."/*");
foreach ($content as $file) {
if (is_dir($file)) {
removeFullDir ($file);
}
else {
unlink($file);
}
}
rmdir($dir);
}
removeFullDir("1");
in localhost (XAMPP server, php version 5.4.4) this code works good. in remote server this code also works, but returns warning:
Warning: Invalid argument supplied for foreach()
in remote server, php version is 5.2.42
please tell me, why obtain I this warning?
This happens because
globdoes not return an array, which means that based on the documentation it must returnfalse. This can happen when there is an error, but it can also happen when the directory happens to be empty:To prevent the notice just guard against it: