S
S
strify_252016-10-22 13:19:24
PHP
strify_25, 2016-10-22 13:19:24

How to count files in a folder on a server?

You need to count the number of files in a certain folder. Everything works on the local computer. Tried two different scripts, both don't work:
1st option
echo count(array_filter(glob("$aAnimate/*"), 'is_file'));
Option 2
$path = '$aAnimate';
$dir = opendir("$path");
$i = 0;
while (false !== ($file = readdir($dir))) {
if (strpos($file, '.jpg',1) ) {
$i++;
}
}
echo "jpg files in folder: ".$i;
The $aAnimate variable contains the path to the folder. Specifically: /upload/primer-animatsii . The rights to folders are 777 and 700, respectively.
I tried to make a file with these codes in the root. The second option works. But I need to display it on the product card (Bitrix). When I transfer - does not work. I also tried to write the path with the site address - it also does not work. The site just takes a very long time to load and then a 503 error occurs.
Please help me solve the problem

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Smirnov, 2016-10-22
@antonzz321

$path = $_SERVER['DOCUMENT_ROOT'].'/images/';
echo count(scandir($path));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question