php 计算php文件夹中的文件数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14194173/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Count number of files in folder in php
提问by Rohit Goel
<?php
$directory = '/var/www/ajaxform/';
if (glob($directory . '.jpg') != false)
{
$filecount = count(glob($directory . '*.jpg'));
echo $filecount;
}
else
{
echo 0;
}
?>
there are four jpg images in this directory but it returns 0
此目录中有四个 jpg 图像,但它返回 0
回答by Michel Feldheim
回答by karlingen
Try this:
尝试这个:
<?php
$directory = '/var/www/ajaxform/';
if (glob($directory . '*.jpg') != false)
{
$filecount = count(glob($directory . '*.jpg'));
echo $filecount;
}
else
{
echo 0;
}
?>
回答by kokx
There is a mistake in your glob pattern (in the if). You are missing a *:
您的 glob 模式中有错误(在 if 中)。您缺少一个 *:
glob($directory . '*.jpg')
should work
应该管用
回答by sbrbot
Minimalization approach:
最小化方法:
function getImagesNo($path)
{
return ($files=glob($path.'*.jpg')) ? count($files) : 0;
}
回答by jimf
glob is case sensitive, according to the PHP docs. Are your extensions lowercase? Does the executing account have access to /var/www/ajaxform/?
根据 PHP 文档,glob 区分大小写。你的扩展名是小写的吗?执行帐户是否可以访问 /var/www/ajaxform/?
回答by Suresh Kamrushi
Just try this--
试试这个——
if (glob($directory . "*.jpg") != false)
$filecount = count(glob($directory . "*.jpg"));
else
$filecount = 0;

