So I've got a folder, path/to/folder
, with folders within folders and files within folders, etc.---all within one folder path/to/folder
. I want to store all the names of all the images (.gif, .png, .jpg, .jpeg, etc.) in this folder path/to/folder
like so (my attempt):
$arr = glob("path/to/folder/*.jpg");//not sure how to specify or "|" here
I also need the dates associated with the images' metadata (date created) like so (see psuedocode below):
foreach($arr as $a){
$date_of_a = function_getting_dates_of_a($a);//filectime?
$newArr[$date_of_a]=function_getting_names_of_a($a);//names are filtered by a pattern
//^^^^^^^^^^^^^^^^^^^^^^^^^^^I've already created this.
}
This way I can have same name values with different keys, which would be dates, and so two same-name-and-same-date pairs (or tuples depending on how many duplicates) would condense to one unique name-date item. For example,
2016-01-01 => path/to/folder/.../name1.jpg//*duplicate name-date pair
2016-01-02 => path/to/folder/.../name2.jpg
2016-01-01 => path/to/folder/.../name1.jpg//*duplicate name-date pair
2016-01-02 => path/to/folder/.../name1.jpg
would reduce the array to
2016-01-01 => path/to/folder/.../name1.jpg//*only one now
2016-01-02 => path/to/folder/.../name2.jpg
2016-01-02 => path/to/folder/.../name1.jpg
Here, /.../
, means "any number of folders within path/to/folder
". The data I'm dealing with would imply that 2016-01-01 => path/to/folder/.../name1.jpg
and 2016-01-02 => path/to/folder/.../name1.jpg
are two identical objects made at different times. I want to, in the end, be able to count how many instances of each name there are using array_count_values
.
ATTEMPT
<?php
$myArray = glob("path/to/folder/*.jpg");
foreach($myArray as $item){
$date = filectime($item);//What if no date? Is that possible?
if(preg_match('/PATTERN/',$item,$match)==1){
$newArr[$date]=current($match);
}
}
array_count_values($newArr);
<!-- CODE TO GRAPH ITEMS BY FREQUENCY-->
?>