<?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
Alternatively, select the folder and press the Alt + Enter keys on your keyboard. When the Properties window opens, Windows 10 automatically starts counting the files and folders inside the selected directory. You can see the number of files and folders displayed in the Contains field.
you can esay and simply get list of file in folder in php. The scandir() function in PHP is an inbuilt function which is used to return an array of files and directories of the specified directory. The scandir() function lists the files and directories which are present inside a specified path.
The is_dir() function in PHP used to check whether the specified file is a directory or not. The name of the file is sent as a parameter to the is_dir() function and it returns True if the file is a directory else it returns False. Parameters Used: The is_dir() function in PHP accepts only one parameter.
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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With