PHP - 检查文件夹中是否存在文件

Jac*_*era 2 php

我想检查我的服务器上的文件夹中是否有任何图像.我在PHP中有这个小功能,但是不工作,我不知道为什么:

$path = 'folder/'.$id;
function check($path) {
    if ($handle = opendir($path)) {
        $array = array();
        while (false !== ($file = readdir($handle))) {
            if ($file != "." && $file != ".." && count > 2) {
                echo "folder not empty";
            } else {
                echo "folder empty";
            }
        }
    }
    closedir($handle);
}
Run Code Online (Sandbox Code Playgroud)

任何帮助将不胜感激,提前感谢.

net*_*der 5

它不起作用,因为count它来自无处.试试这个:

$path = 'folder/'.$id;
function check($path) {
    $files = glob($path.'/*');
    echo empty($files) ? "$path is empty" : "$path is not empty";
}
Run Code Online (Sandbox Code Playgroud)