Friday, March 3, 2017

Laravel File In Directory Loop Doesn't Include 3,4,7,8,9 and 11

So a couple of months ago I made this simple image uploader with Laravel, however today I noticed that some of the "recent uploaded" images I am calling with a loop (RecentImagesController.php) through my upload folder, doesn't seem to be shown based on the following numbers:

03,04,07,08,09 and 11

However if I change the folder number to 01,02,05,06,10 or 12 then the content does get shown.

This is the loop that I have currently:

namespace App\Http\Controllers;
use File;
class RecentImagesController extends Controller{
    public function recentImages(){
        $thumbPath = public_path('up/').date("Y/m").'/thumbs/';
        File::isDirectory($thumbPath) or File::makeDirectory($thumbPath,0775,true,true);
        foreach(array_reverse(File::directories("up")) as $dirYears){
            foreach(File::directories($dirYears) as $dir){
                foreach(array_reverse(File::files($dir)) as $path){
                    $files[] = pathinfo($path);
                }
            }
        }
    return view("recent-images-view")->with("files",$files);
    }
}

I'm not exactly sure to why this works with some numbers, and specifically not with those other numbers, or at least I can't directly spot the pattern into why this is happening.

The application as it is can be found here: https://ap-images.ga/recent And all the files in the following github repo: https://github.com/RafaelDeJongh/AP-Images

However I think it's purely something to do with the loop (https://github.com/RafaelDeJongh/AP-Images/blob/master/app/Http/Controllers/RecentImagesController.php) yet I am not exactly sure to what this problem is.

So to anyone who could help me further with this "problem" I thank you already in advance.



via Rafaƫl De Jongh

Advertisement