I want to check if a folder has at least 1 file. I am now using this to check if a folder is empty but this also checks if there is a subfolder in it.
if (count(glob($dir.'/*')) === 0 ) {}
And I only want to check for files in it
I want to check if a folder has at least 1 file. I am now using this to check if a folder is empty but this also checks if there is a subfolder in it.
if (count(glob($dir.'/*')) === 0 ) {}
And I only want to check for files in it
You can achieve it by using opendir
and readdir
function check_file($dir) {
$result = false;
if($dh = opendir($dir)) {
while(!$result && ($file = readdir($dh)) !== false) {
$result = $file !== "." && $file !== ".." && !is_dir($file);
}
closedir($dh);
}
return $result;
}
$dir="/var/www/html/jkjkj/";// your path here
echo check_file($dir);// return 1 if file found otherwise empty