Posted inTechnology / Ajax / jQuery / Mysql / php / Programming

Ajax Upload Multiple Images without form submitting

Today, We want to share with you Ajax Upload Multiple Images without form submitting.In this post we will show you PHP Ajax Multiple Image Upload with Preview Example, hear for Uploading files/image with Ajax & Jquery, without submitting a form we will give you demo and example for implement.In this post, we will learn about Ajax Image Upload using PHP and jQuery Example Without Page Refresh with Validation with an example.

Ajax Upload Multiple Images without form submitting

There are the Following The simple About Ajax Upload Multiple Images without form submitting Full Information With Example and source code.

As I will cover this Post with live Working example to develop How to upload a file in Ajax without using a form in PHP, so the some Upload Multiple Images Using PHP and jQuery for this example is following below.

Example 1: Jquery Ajax Uploading image without submitting a form

HTML Part


jQuery Part

$(document).on("click", "#upload", function() {
	var file_data = $("#profile").prop("files")[0];   
	var profile_form_data = new FormData();                
	profile_form_data.append("file", file_data)            
	profile_form_data.append("user_name", "jaydeep Gondaliya")                 
	$.ajax({
                url: "/members_profile_avatar",
                dataType: 'script',
                cache: false,
                contentType: false,
                processData: false,
                data: profile_form_data,                         
                type: 'post'
       })
})

Example 2: Ajax Multiple Image upload using jQuery and PHP

index.php

Ajax Image upload - PHP Mysql

custom.js

function fileread(file) {
var fsize = file.files[0].size;
var fileimgName = file.files[0].name;
var fileimgtype = file.files[0].type;
 var fileimgArr = ["image/png", "image/jpeg", "image/gif", "image/jpg"];
 var fileTrue = fileimgArr.indexOf(fileimgtype);
if(fileTrue>=0){
 var reader = new FileReader();
 reader.element = $(file).parent().find('imgThumbals');
 reader.onload = function(e) {
 var div = document.getElementById("imgThumbals");
 div.innerHTML = "Ajax Upload Multiple Images without form submitting";

var formData = new FormData();
 for (var i = 0; i < file.files.length; i++) {
 var fileup = file.files[i];
 if (!fileup.type.match('image.*')) {
 continue;
 }
 // Add the file to the request.
 formData.append('memberprofilename[]', fileup, fileup.name);

}
 fileImgUpload(formData)
 };
 reader.onerror = function(e) {
	alert("error: " + e.target.error.code);
 };
 reader.readAsDataURL(file.files[0]);
 }else{
 document.getElementById("error").innerHTML = "Incorrect file format, Please select an image file format..";
}
 }


 function fileImgUpload(formData){
 var xhr = new XMLHttpRequest();
xhr.open('POST', 'upload.php', true);
xhr.onload = function () {
 if (xhr.status === 200) {
 //console.log(xhr.responseText);
 } else {
 alert('An error occurred!');
 }
};

xhr.upload.addEventListener("progress", profile_imgprogress, false);
xhr.addEventListener("load", Completed, false);
xhr.addEventListener("error", failstatus, false);
 xhr.addEventListener("abort", Abortedstatus, false);
xhr.send(formData);

}

 function profile_imgprogress(event){
 document.getElementById('profile_complete').style.display = 'none';
document.getElementById('profile_uploaded_status').style.display = 'block';

 var percent = (event.loaded / event.total) * 100;
 document.getElementById("status").value = Math.round(percent);
 $("#progressbar").progressbar({value: document.getElementById("status").value});
 document.getElementById("status").innerHTML = Math.round(percent)+"%";
}

upload.php

';
 echo "
Your Profile Successfully uploaded.
"; } ?>
Angular 6 CRUD Operations Application Tutorials

Read :

Summary

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

I hope you get an idea about Ajax Upload Multiple Images without form submitting.
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.

I am Jaydeep Gondaliya , a software engineer, the founder and the person running Pakainfo. I'm a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, JavaScript, jQuery, Laravel, CodeIgniter, VueJS, AngularJS and Bootstrap from the early stage.

Leave a Reply

Your email address will not be published. Required fields are marked *

We accept paid guest Posting on our Site : Guest Post Chat with Us On Skype