0

I want to show all images that are in a particular folder, I have the folder path but I do not see how the number of images there are inside and how show all. Someone could help me?

1 Answer 1

3

If your files are inside public or a subfolder of it, this is is a way:

foreach (File::allFiles(public_path().'/assets/img/') as $file)
{
    $filename = $file->getRelativePathName();

    echo HTML::image('public/assets/img/'.$filename, $filename);
}

This is a router you can use to test it:

Route::any('images', function() {

    $images = '';

    foreach (File::allFiles(public_path() . '/assets/img/') as $file) 
    {
        $filename = $file->getRelativePathName();

        $images .= HTML::image('public/assets/img/'.$filename, $filename);
    }

    return "<htm><body>$images</body></htm>";

});

Edit the /assets/img/ to your own and just hit http://yourserver.dev/images.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.