• We just launched and are currently in beta. Join us as we build and grow the community.

Ajax Select and Upload Multiple Images

jamo

Shonen Battle Strategist
J Rep
0
0
0
Rep
0
J Vouches
0
0
0
Vouches
0
Posts
57
Likes
143
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 400 XP
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 Database Table

  1. CREATE

    TABLE

    `user_uploads`

    (
  2. `id`

    INT

    (

    11

    )

    NOT

    NULL

    ,
  3. `image_name`

    VARCHAR

    (

    100

    )

    NOT

    NULL

    ,
  4. `user_id`

    INT

    (

    11

    )

    NOT

    NULL

    ,
  5. `date_upload`

    VARCHAR

    (

    100

    )

    NOT

    NULL
  6. )

    ENGINE=

    InnoDB DEFAULT

    CHARSET=

    latin1;

Creating Markup

1_144.png

Creating form field where the user can select images to upload.
  1. <div

    align

    =

    "center"

    >

  2. <div

    id

    =

    'preview_Upload_images'

    >
  3. </

    div

    >

  4. <form

    id

    =

    "form_Images"

    method

    =

    "post"

    enctype

    =

    "multipart/form-data"

    action

    =

    'ajaxImageUpload.php'

    style

    =

    "clear:both"

    >
  5. <h1

    >

    Upload your images</

    h1

    >
  6. <div

    id

    =

    'status_image_Loading'

    style

    =

    'display:none'

    ><img

    src

    =

    "loader.gif"

    alt

    =

    "Uploading...."

    /

    ></

    div

    >
  7. <div

    id

    =

    'button_Image_loading'

    >
  8. <input

    type

    =

    "file"

    name

    =

    "photos[]"

    class

    =

    "file_image"

    id

    =

    "image_Photo"

    multiple

    =

    "true"

    /

    >
  9. </

    div

    >
  10. </

    form

    >

  11. </

    div

    >

JavaScript Source Code

Kindly copy and paste this script and link to your HEAD tag of your page.
  1. <script

    src

    =

    "js/jquery.min.js"

    ></

    script

    >
  2. <script

    src

    =

    "js/jquery.wallform.js"

    ></

    script

    >
  3. <script

    >
  4. $(document).ready(function() {

  5. $('#image_Photo').die('click').live('change', function() {
  6. //$("#preview_Upload_images").html('');

  7. $("#form_Images").ajaxForm({target: '#preview_Upload_images',
  8. beforeSubmit:function(){

  9. console.log('ttest');
  10. $("#status_image_Loading").show();
  11. $("#button_Image_loading").hide();
  12. },
  13. success:function(){
  14. console.log('test');
  15. $("#status_image_Loading").hide();
  16. $("#button_Image_loading").show();
  17. },
  18. error:function(){
  19. console.log('xtest');
  20. $("#status_image_Loading").hide();
  21. $("#button_Image_loading").show();
  22. } }).submit();
  23. });
  24. });
  25. </

    script

    >

Was this article helpful?

Kindly click the "Download Code" button below for full source code. Thank you very much.

Hope that this tutorial will help you a lot.

Share us your thoughts and comments below. Thank you so much for dropping by and reading this tutorial post. For more updates, don’t hesitate and feel free to visit this website more often and please share this with your friends or email me at [email protected]. Practice Coding. Thank you very much.


Download
You must upgrade your account or reply in the thread to view hidden text.
 

452,292

323,341

323,350

Top