A minimal PHP example that uploads an image from an HTML form, stores the file
in a local images/ folder on the server, records its path in a MySQL database,
and then displays all uploaded images on the index page.
- Simple upload form (
upload.php) with server-side validation - Allowed types restricted to
jpg,jpeg,png,gif - File-size limit (< 1 MB) and upload-error checks
- Unique filenames via
uniqid(); files saved underimages/ - Image paths stored in a MySQL
imagestable - Gallery view (
index.php) that lists every stored image
- PHP (MySQLi)
- MySQL / MariaDB
- HTML
index.php # reads image paths from the DB and displays them
upload.php # upload form + handler (validation, move, DB insert)
babylow.sql # database + `images` table schema
images/ # uploaded files are stored here
- Serve the folder with PHP + MySQL (e.g. XAMPP / MAMP), reachable via a browser.
- Create the database and table:
mysql -u root < babylow.sql - Update the
mysqli_connect(...)credentials inindex.phpandupload.phpif your MySQL user/password differ from the local defaults. - Open
upload.phpto upload an image, thenindex.phpto see the gallery.
Note: the database credentials in the source are local development defaults (
root/ empty password). Set real credentials for any real deployment, and treat this as a learning example rather than production-ready upload code.