I have in folder "files" some folders. I want to return the count of this folders by my php code:
$x = count(scandir('/files'));
echo $x;
But this is not working. What is wrong?
I have in folder "files" some folders. I want to return the count of this folders by my php code:
$x = count(scandir('/files'));
echo $x;
But this is not working. What is wrong?
If you have some files in files folder, Here is the solution.
$directory = 'files/';
$scanned_directory = array_diff(scandir($directory), array('..', '.'));//to remove dots
$x = count($scanned_directory);
echo $x;
Try not to use /files. It will look for the file named files
Try this:
$directory = '/your/directory/path/';
$files = glob($directory . '*.*'); // returns an array on success and false on error.
if ( $files !== false )
{
$filecount = count( $files );
echo $filecount;
}
else
{
echo 0;
}
its better to check if directory does even exist first :
$directory = '/your/directory/path/';
if(!is_dir($directory))
die("direction not exists");
ant then count and remove .
and ..
elements