Ajax Select and Upload Multiple Images
Submitted by alpha_luna on Wednesday, June 22, 2016 - 16:06.
In my last tutorial, I had posted an article about Multiple File and Drop Upload using HTML5 and jQuery. In this article, the user allows to select and upload multiple images in a single shot.
Creating form field where the user can select images to upload.
Creating Database Table
- CREATE TABLE `user_uploads` (
- `id` INT(11) NOT NULL,
- `image_name` VARCHAR(100) NOT NULL,
- `user_id` INT(11) NOT NULL,
- `date_upload` VARCHAR(100) NOT NULL
- ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Creating Markup

- <div align="center">
- <div id='preview_Upload_images'>
- </div>
- <form id="form_Images" method="post" enctype="multipart/form-data" action='ajaxImageUpload.php' style="clear:both">
- <div id='button_Image_loading'>
- <input type="file" name="photos[]" class="file_image" id="image_Photo" multiple="true" />
- </div>
- </form>
- </div>
JavaScript Source Code
Kindly copy and paste this script and link to your HEAD tag of your page.- <script>
- $(document).ready(function() {
- $('#image_Photo').die('click').live('change', function() {
- //$("#preview_Upload_images").html('');
- $("#form_Images").ajaxForm({target: '#preview_Upload_images',
- beforeSubmit:function(){
- console.log('ttest');
- $("#status_image_Loading").show();
- $("#button_Image_loading").hide();
- },
- success:function(){
- console.log('test');
- $("#status_image_Loading").hide();
- $("#button_Image_loading").show();
- },
- error:function(){
- console.log('xtest');
- $("#status_image_Loading").hide();
- $("#button_Image_loading").show();
- } }).submit();
- });
- });
- </script>