DEV Community

Cover image for Image gallery without database
Marcos Silva
Marcos Silva

Posted on • Updated on

Image gallery without database

This image gallery was developed using only PHP in the beckend, it is not necessary to use a database. As for the frontend, it was developed using only HTML, CSS and JavaScript.

how is it possible not to use DB?

This is possible thanks to the FilesystemIterator class, this class is native to PHP and it returns a list of files and folders that are inside the directory informed in its constructor. Note: this instance of FilesystemIterator, as its name suggests, is iterable as an array, that is, it can be used directly in a repetition structure such as for (), foreach () and etc.. See the example:

<?php
$files = new FilesystemIterator(
    __DIR__.'/public/assets/img'
);
foreach($files as $file){
    echo $file
        ->getFilename().PHP_EOL;
}
Enter fullscreen mode Exit fullscreen mode

The above code will print:

folder-2741806_1280.png
gallery
icons
screenshot
top_directory.png
wall-2558279_1920.jpg
Enter fullscreen mode Exit fullscreen mode

If interested, please leave your review.
This is my repository with the complete gallery, including the secure upload of images, administration panel to execute CRUD of galery or images. let your star if like the idea
Image Gallery Without database
By my code do you imagine that I can be the junior developer?

Sorry my English, blame Google Translate. :tw-1f605:

Discussion (0)