A file upload form built with PHP and MySQL. Includes admin login, role-based access control, and file management. Uses PDO for all database interactions.
- Secure Admin Area — only authenticated users with the
adminrole can access the upload functionality - File Upload — validates MIME type (JPEG, PNG, GIF, PDF) and enforces a 5 MB size limit before saving to
uploads/ - File Listing — displays uploaded files after login
- Admin Management — optional registration page for creating additional admin accounts (requires an existing admin session)
- Secure Code — prepared statements throughout, passwords hashed with
password_hash
- PHP 7.4 or higher (Apache or Nginx)
- MySQL 5.7+ / MariaDB
-
Clone the repository:
git clone https://github.com/marinnedea/dynamic-PHP-MySQL-jQuery-upload-form.git cd dynamic-PHP-MySQL-jQuery-upload-form -
Set up the database:
mysql -u your_username -p your_database < accounts.sql -
Configure database credentials — edit
config.php:$dsn = 'mysql:host=your_host;dbname=your_database;charset=utf8mb4'; $db_user = 'your_username'; $db_pass = 'your_password';
-
Set directory permissions:
mkdir uploads chmod 755 uploads
-
Bootstrap the first admin user:
- Temporarily comment out the session guard in
register.php(see the comment in that file) - Visit
register.php, create your admin account - Uncomment the guard again
- Temporarily comment out the session guard in
-
Access the project:
login.php— admin loginindex.php— upload area (admin only)register.php— create additional admin accounts (admin only)
dynamic-PHP-MySQL-jQuery-upload-form/
├── config.php # Database connection (edit credentials here)
├── index.php # File upload area (admin only)
├── login.php # Admin login page
├── register.php # Create additional admin accounts (admin only)
├── logout.php # Ends the session
├── accounts.sql # Creates the users and uploads tables
├── uploads/ # Uploaded files are stored here
├── CHANGELOG.md # Version history
└── README.md
- Authentication — session-based, all protected pages redirect to
login.phpif not logged in - Role-based access — only users with
role = admincan reachindex.phpandregister.php - File validation — MIME type and size checked server-side before the file is accepted
- SQL injection prevention — all queries use PDO prepared statements
- Password hashing —
password_hash/password_verifywithPASSWORD_DEFAULT
- Add a progress bar for file uploads
- Allow admin users to delete uploaded files
- Improve the UI with a CSS framework (e.g., Bootstrap or Tailwind)
MIT — see LICENSE.