Ad
Laravel File Listing & Counting By Filtered File Names
I want to count the number of files I filter by name. I wrote the following code:
<?php
$directory = Config::get('app.app_working_directory')."/".$form_constant["dir"];
foreach(File::allFiles($directory) as $file)
{
if (starts_with($file->getFilename(), $file_tag."-".$id)) {
?>
{{HTML::image($form_constant["dir"].'/'.$file->getFilename(), $id, array('class' => 'col-md-3 img-thumbnail img-responsive'))}}
<?php
}
}
?>
But this is just for listing files on directory. My stored files like this:
machine-parts-103-09122015150511.jpg
machine-parts-103-09122015150515.jpg
machine-parts-1072-09122015143157.jpg
Format: machine-part-$id-microtime(). How I can count like a just filename starting "machine-part-$id-"? Example for this file names: "Total File:2" for "machine-parts-103-". Thanks...
Ad
Answer
You could use the glob function to count the number of files that matches a wildcard like this:
glob("/path/to/directory/machine-parts-103-*.jpg");
This will return you an array with all the files names that matches that pattern and you can count the number of items in the array.
Ad
source: stackoverflow.com
Related Questions
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?
Ad