检查文件夹是否为空输出错误(PHP)
我有一个代码来检查目录是否为空,以便我能够执行操作,但是这个简单的代码给出了一个错误:
<块引用>警告: opendir(/Site/images/countries/abc/a/2.swf,/Site/images/countries/abc/a/2.swf) [function.opendir]:系统找不到指定的路径。 (代码:3)在 C:\wamp\www\Site\index.PHP 第 374 行
没有这样的文件
function IsNotEmpty($folder){
$files = array ();
if ( $handle = opendir ( $folder ) )
{
while ( false !== ( $file = readdir ( $handle ) ) )
{
if ( $file != "." && $file != ".." )
{
$files [] = $file;
}
}
closedir ( $handle );
}
return ( count ( $files ) > 0 ) ? TRUE: FALSE; }
$dir ="/Site/images/countries/abc/a/2.swf";
if (IsNotEmpty($dir)==true)
{
echo "There is no such file";
}
else
{
echo "The file exists!";
};
我不明白这里出了什么问题。文件存在于指定目录中。
I have a code to check if directory is empty, so that i will be able to perform actions, but this simple code gives an error:
Warning: opendir(/Site/images/countries/abc/a/2.swf,/Site/images/countries/abc/a/2.swf) [function.opendir]: The system cannot find the path specified. (code: 3) in C:\wamp\www\Site\index.PHP on line 374
There is no such file
function IsNotEmpty($folder){
$files = array ();
if ( $handle = opendir ( $folder ) )
{
while ( false !== ( $file = readdir ( $handle ) ) )
{
if ( $file != "." && $file != ".." )
{
$files [] = $file;
}
}
closedir ( $handle );
}
return ( count ( $files ) > 0 ) ? TRUE: FALSE; }
$dir ="/Site/images/countries/abc/a/2.swf";
if (IsNotEmpty($dir)==true)
{
echo "There is no such file";
}
else
{
echo "The file exists!";
};
I don't understand what is wrong here. The file exits in the specified directory.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
opendir
用于打开目录,而不是文件:-)您还可以尝试暂时放入调试内容,以便您可以看到发生了什么:
如果仍然不起作用并且您确定该目录存在(记住,大小写对于 UNIX 很重要),您可能需要查看该目录的权限以确保允许尝试访问该目录的用户 ID。
opendir
is for opening directories, not files :-)You can also try temporarily putting in debug stuff so that you can see what's happening:
If that's still not working and you're sure the directory exists (remember, case is important for UNIX), you may want to look into the permissions on that directory to ensure that the user ID trying to access it is allowed.
您可以使用以下代码片段作为函数的主体:
这将以数组形式获取文件夹的内容,当为空时 - 您的目录为空。
You chould use the following snippet as body for your function:
This will get the contents of the folder as an array, when empty - your directory is empty.
试试这个:
Try for instance this:
克里斯汀,尝试删除尾部斜线:
成为
Christine, try removing the trailing slash:
Becomes