Hello Amigos! You will learn how to upload files in plain PHP in this article.
This article covers
If you have read my other article on How To Upload Image In PHP? then this one is also similar to that with few modifications in validating the file instead instead of image.
_I have hosted this in GitHub. Feel free to you use is any of your project _Invoice File Upload Demo
Basic PHP, Database & HTML knowledge.
I have written another article proper way to validate the file in PHP Proper Way To Validate MIME Type Of Files While Handling File Uploads In PHP. Don’t miss it.
First let me clear you few concepts, we can store the files/images in database as blob but we wont be doing that.
We will store the files/images in specific path of project. Why?
Following is the database design for our testing. As you see its very simple design. For the sake of example we have taken **invoice**
as database name.
/** Creating database with name invoice */
CREATE DATABASE `invoice`;
/** Once we create we want to switch to invoice so that we can add products table */
USE `invoice`;
/** Products table to hold the products data */
CREATE TABLE `products` (
`id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`name` VARCHAR(30),
`product_invoice` VARCHAR(255),
PRIMARY KEY (`id`)
);
NOTE: For the sake of demonstration I am just using Product Invoice as the purchase invoice. It doesn’t make any sense but at the end you will be clear with
For the sake of simplicity lets the file upload only take image, pdf, xls
Since we have only 2 fields other than id in our database table products we will have only 2 fields in HTML form.
I wont be using bootstrap or anything for this it will be plain HTML code.
Following is my folder structure
#php #html