Ajax Image Upload with Form Data using jQuery, PHP and MySQL

Uploading Image from client to server is one of the most popular features of any web application. jQuery and Ajax can be used to upload images without page refresh. In this tutorial, We have share Ajax Image Upload with Form Data using jQuery, PHP and MySQL.
The FormData object lets you compile a set of key/value pairs to send using XMLHttpRequest. It is primarily intended for use in sending form data, but can be used independently from forms in order to transmit keyed data. The transmitted data is in the same format that the form’s submit() method would use to send the data if the form’s encoding type were set to multipart/form-data.
Step 1: Create MySQL Database and Table
The following SQL creates a upload_file table in the MySQL database.
Step 2: Database Configuration (constants.php abd DBConnection.php)
The constants.php file is defined constants.
The DBConnection.php file is used to connect the MySQL database
Step 3: Create File (index.php)
The following code shows the HTML for the image upload form.
Step 4: Create File (common.js)
The following code using $ajax() method for send data to php also check the success data or error in data sending.
Step 5: Upload File & Insert Form Data (action.php and Upload.php)
  • Upload File action.php
  • Insert Data (Upload.php)
You can view the live demo from the Demo link and can download the script from the Download link below.