7

I am using manual uploading via Fine Uploader. Now i want to check that file has selected or not.

$(document).ready(function() {
    var fineuploader = new qq.FineUploader({
        element: $('#fine-uploader')[0],
        request: {
            endpoint: '<?php echo site_url('pl_items/upload_images');?>'
        },
        multiple: true,
        autoUpload: false,
        onLeave: false,
        validation: {
            allowedExtensions: ['jpeg', 'jpg', 'gif', 'png'],
            sizeLimit: 5120000 // 50 kB = 50 * 1024 bytes
        },
        text: { 
            uploadButton: '<i class="icon-plus icon-white"></i> Select Files' 
        },
        template: '<div class="qq-uploader">' +
                  '<pre class="qq-upload-drop-area"><span>{dragZoneText}</span></pre>' +
                  '<div class="qq-upload-button btn btn-danger">{uploadButtonText}</div>' +
                  '<div class="qq-drop-processing span1"><span>{dropProcessingText}</span><span class="qq-drop-processing-spinner"></span></div>' +
                  '<div><ul class="qq-upload-list"></ul></div>' +
                   '</div>',
        callbacks: {
            onComplete: function(id, name, response) {
                $('#frmDetails').append('<input type="hidden" name="pl_item_images[]" value="'+response.file_name+'">');
                //$("#frmDetails").submit();
            }
        },
    });

    $('#submit_button').click(function() {
        fineuploader.uploadStoredFiles();
    });
});
Ray Nicholus
  • 19,538
  • 14
  • 59
  • 82
Raju Singh
  • 750
  • 8
  • 21
  • Where do you want to check the number of selected files, and why? – Ray Nicholus Jun 18 '13 at 18:09
  • Well I have come across the same problem ! Is it possible to know the total number of images selected and they are rendered/loaded in the preview box (either preview is available or not) ! I want to disable the upload button until all the images are loaded correctly. – rajug Jun 18 '19 at 08:44

1 Answers1

11

Since you haven't responded to my question, I'll just assume that you want to determine if a file has been selected before you call uploadStoredFiles in your click handler.

It's really very simple. Just make use of the getUploads API method. For example, you could change your click handler to look like this:

$('#submit_button').click(function() {
    var submittedFileCount = fineuploader.getUploads({status: qq.status.SUBMITTED}).length;

    if (submittedFileCouunt > 0) {
        fineuploader.uploadStoredFiles();
    }
});

A few more things:

  • There is no onLeave option. You should remove this from your code.
  • The multiple option defaults to true. You can remove this from your code as well.
  • You are already using jQuery. Why aren't you using the Fine Uploader jQuery plug-in? See the documentation for instructions.
Ray Nicholus
  • 19,538
  • 14
  • 59
  • 82
  • Thank you Ray, this was helpful to me! – Sébastien Richer Jun 21 '13 at 18:16
  • If this solved your problem, please consider accepting my answer. – Ray Nicholus Jun 21 '13 at 18:17
  • I'm not that user though hehe, I upvoted you answer, but that's all I can do hehe. Hey any reason why my "qq" variable would not have a .STATUS? – Sébastien Richer Jun 21 '13 at 18:24
  • @SébastienRicher Yes. The most likely cause is you are using a version of Fine Uploader older than 3.6. Also, the property is `status`, and not `STATUS`. – Ray Nicholus Jun 21 '13 at 18:33
  • 1
    Your code will not work. You have a typo error in variable name "submittedFileCouunt". :P... anyway good answer. – nrsharma Sep 22 '15 at 10:19
  • In my case, there is no form submit button, i have a browse button functionality which uploads selected files then how can i get number of files before starting uploading process? Please suggest me. Thank you. – Kamlesh Dec 13 '19 at 11:40