3
0 Comments

Wizard's Toolkit: File Display function from PHP low-code development library

Wizard's Toolkit is a library of PHP functions to make building responsive-designed websites and hybrid mobile apps quick and easy. This library was started in 2009 and has been enhanced and grown over the years.

This video gives a complete code walk-through and showcases the File Display function.

https://www.youtube.com/watch?v=pIJfRXWncQQ

Almost all websites need to show a gallery of images, PDFs and/or videos. Sometimes those are stored in a database, and sometimes you may want to just show all files that are in a folder and sub-folders.

First we examine pulling the information from a SQL database. The SQL script retrieves the locations of the user images and path to that image.

In PHP we use PDO to pull in the data into a PHP array. Then just pass that array to wtkFileDisplay and it returns the HTML to evenly distribute the images in a nice viewing grid. The function dynamically determines the optimal number to show per row but you can override that.

For this example we are using MaterializeCSS which has a nice lightbox effect for images.

Next we look at the wtkReadDir function which can be used to get a listing of files from a directory and it's subdirectories. You can pass in a specific file extension to search for, or use the special 'image' or 'video' value to find all image file types or video file types. If you want to check specific directory instead of the directory your PHP file is in, you can.

Of course you can merge multiple arrays using array_merge_recursive then pass to wtkFileDisplay and voila, you have a combination of videos, images and PDFs. Likewise you could also pull from your SQL database and merge it into the array and display.

Last thing to note, the wtkFileDisplay function uses wtkFileCell to generate the HTML based on file type. The wtkFileCell uses wtkInsertSpaces on the file name to make it more user-friendly. The wtkInsertSpaces function adds a space between words based on WordCaps or snake_case. That way when you change a file name in the folder it displays nicely on the web page. This wtkInsertSpaces is used by many other functions in Wizard's Toolkit to save developers huge amounts of time.

Wizard's Toolkit - Low-code library of PHP, SQL and JavaScript
https://WizardsToolkit.com

posted to Icon for group PHP
PHP
on March 10, 2022
Trending on Indie Hackers
I shipped 3 features this weekend based entirely on community feedback. Here's what I built and why. User Avatar 146 comments $36K in 7 days: Why distribution beats product (early on) User Avatar 127 comments I'm a lawyer who launched an AI contract tool on Product Hunt today — here's what building it as a non-technical founder actually felt like User Avatar 126 comments Finally reached 100 users in just 12 days 🚀 User Avatar 123 comments I realized showing problems isn’t enough — so I built this User Avatar 32 comments 👉 The most expensive contract mistakes don’t feel risky User Avatar 28 comments