<?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
<?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
Glob returns an array
, on error it returns false
.
Try this:
$directory = '/var/www/ajaxform/';
$files = glob($directory . '*.jpg');
if ( $files !== false )
{
$filecount = count( $files );
echo $filecount;
}
else
{
echo 0;
}
Try this:
<?php
$directory = '/var/www/ajaxform/';
if (glob($directory . '*.jpg') != false)
{
$filecount = count(glob($directory . '*.jpg'));
echo $filecount;
}
else
{
echo 0;
}
?>
There is a mistake in your glob pattern (in the if). You are missing a *:
glob($directory . '*.jpg')
should work
Minimalization approach:
function getImagesNo($path)
{
return ($files=glob($path.'*.jpg')) ? count($files) : 0;
}
glob is case sensitive, according to the PHP docs. Are your extensions lowercase? Does the executing account have access to /var/www/ajaxform/?
Just try this--
if (glob($directory . "*.jpg") != false)
$filecount = count(glob($directory . "*.jpg"));
else
$filecount = 0;