jQuery Ajax Image Upload without Page Refresh using PHP

Today, We want to share with you jQuery Ajax Image Upload without Page Refresh using PHP.
In this post we will show you Ajax file upload, hear for simple ajax file upload jquery we will give you demo and example for implement.In this post, we will learn about Image Upload without Page Refresh with PHP and jQuery with Demo with an example.

jQuery Ajax Image Upload without Page Refresh using PHP

There are the Following The simple About jQuery Ajax Image Upload without Page Refresh using PHP Full Information With Example and source code for PHP Image Upload without Page Refresh and jQuery Tutorials.

Also Read :  jQuery Ajax File Upload images using PHP MySQLi

Main HTML Interface for Image Upload

index.php

<div class="upload_container">
<br clear="all" />
<center>
<div style="width:450px" align="center">
<div id='img_preview'></div>
<form id="profile_images_upload_frm" method="post" enctype="multipart/form-data" action='profile_images_upload.php' autocomplete="off">
<div class="browse_text">Select You Profile Image File:</div>
<div class="file_input_container">
<div class="pakainfo upload_button"><input type="file" name="client_profile" id="client_profile" class="file_input" /></div>
</div><br clear="all">
</form>
</div>
</center>
<br clear="all" />
</div>

clients Table

CREATE TABLE IF NOT EXISTS `clients` (
`clientid` int(11) NOT NULL AUTO_INCREMENT,
`client` varchar(255) DEFAULT NULL,
`pass` varchar(100) DEFAULT NULL,
`email` varchar(255) DEFAULT NULL,
`profile_photo` varchar(200) DEFAULT NULL,
PRIMARY KEY (`clientid`),
UNIQUE KEY `username` (`client`),
UNIQUE KEY `email` (`email`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

profile_images_upload.php

<?php
$path = "medias/";
$file_format_valid_check = array("jpg", "png", "gif", "bmp","jpeg");
if(isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST")
{
$name = $_FILES['client_profile']['name'];
$size = $_FILES['client_profile']['size'];
if(strlen($name)) {
list($txt, $ext) = explode(".", $name);
if(in_array($ext,$file_format_valid_check)) {
if($size<(1024*1024)) {
$client_profile_name = time().$client_session_id.".".$ext;
$tmp = $_FILES['client_profile']['tmp_name'];
if(move_uploaded_file($tmp, $path.$client_profile_name)){
mysql_query("UPDATE clients SET profile_photo='$client_profile_name' WHERE clientid='$client_session_id'");
echo "<img src="https://pakainfo.com/jquery-ajax-image-upload-without-page-refresh-using-php/medias/%22.client_profile_name" class='img_preview'>";
}
else
echo "sorry, client_profile Upload failed";
}
else
echo "client_profile file size maximum 1 MB, please try again.";
}
else
echo "Invalid your uploaded file format";
}
else
echo "Please select your Good Profile image";
exit;
}
?>

upload.js

Also Read :  Laravel Get Real client IP address from request

The file main jQuery upload.js Data contains source code to HTML submit form when your pictures file uploaded to fully submit pictures upload futures with profile_images_upload.php. The file also displays pictures upload main wait loader.

$(document).ready(function() {
$('#client_profile').live('change', function() {
$("#img_preview").html('');
$("#img_preview").html('<img src="https://pakainfo.com/loader.gif" alt="Yout Profile Image Uploading...."/>');
$("#profile_images_upload_frm").ajaxForm({
target: '#img_preview'
}).submit();
});
});

Read :

Angular 6 CRUD Operations Application Tutorials

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Ajax Image Upload without Refreshing Page using Jquery.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Recommended For You.

Laravel 5.7 Queues Send Mail Tutorial With Example From Scratch
Today, We want to share with you Laravel 5.7 Queues Send Mail Tutorial With Example From Scratch.In this post we