How to count file of category in codeigniter?

Member

by rollin , in category: PHP Frameworks , 4 months ago

How to count file of category in codeigniter?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by dedrick , 4 months ago

@rollin 

To count the number of files in a specific category in CodeIgniter, you can use the following code:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// Load the file helper
$this->load->helper('file');

// Specify the directory where your files are stored
$directory = './path/to/files/';

// Specify the category you want to count files for
$category = 'category_name';

// Get the list of files in the directory
$files = get_filenames($directory);

// Initialize a counter
$count = 0;

// Loop through the files and count the files in the specified category
foreach ($files as $file) {
    if (strpos($file, $category) !== false) {
        $count++;
    }
}

// Display the count
echo 'Number of files in category ' . $category . ': ' . $count;


Replace './path/to/files/' with the actual path to the directory where your files are stored, and 'category_name' with the name of the category you want to count files for.


This code will loop through the files in the specified directory and count the files that contain the category name in their filename.