我必须检查我的文件夹 Assets /文件是否为空以显示创建新文件的消息或列出文件夹中的所有文件..但我的文件夹是空的并且我收到消息“您有文件”..
<?php
/**
* FileExist
* check files
* @return no
*/
public function fileExist()
{
$open = "../asset/files";
if (scandir($open)) {
echo "`You got files";
print_r(scandir($open));
} else {
echo "You haven't got files";
}
}
?>
最佳答案
这应该适合你:
(这里我只是使用 glob()
来获取目录的所有文件并检查它是否为空。您的方法不起作用,因为 scandir()
还包括 .
和 ..
)
public function fileExist()
{
$open = "../asset/files";
if ($files = glob($open . "/*")) {
echo "You got files";
print_r($files);
} else {
echo "You haven't got files";
}
}
关于php - 检查文件夹是否为空 php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29194627/