jquery file upload restricting number of files










16















I am using jquery file upload to upload the files to the server . I want to restrict the user to upload maximum 6 files . I search the wiki jquery file upload but didnt find the parameter for it . Is there any way that i can restrict the user on number of uplaods










share|improve this question






















  • which jquery plugin you are using? generally inside callback function it will hold those files in some sort of json array whose size you can put in if() clause

    – Abhishek K
    Apr 15 '13 at 9:07











  • A why not working version: stackoverflow.com/questions/21347805/…

    – Ciro Santilli 新疆改造中心 六四事件 法轮功
    Nov 8 '14 at 9:33















16















I am using jquery file upload to upload the files to the server . I want to restrict the user to upload maximum 6 files . I search the wiki jquery file upload but didnt find the parameter for it . Is there any way that i can restrict the user on number of uplaods










share|improve this question






















  • which jquery plugin you are using? generally inside callback function it will hold those files in some sort of json array whose size you can put in if() clause

    – Abhishek K
    Apr 15 '13 at 9:07











  • A why not working version: stackoverflow.com/questions/21347805/…

    – Ciro Santilli 新疆改造中心 六四事件 法轮功
    Nov 8 '14 at 9:33













16












16








16


3






I am using jquery file upload to upload the files to the server . I want to restrict the user to upload maximum 6 files . I search the wiki jquery file upload but didnt find the parameter for it . Is there any way that i can restrict the user on number of uplaods










share|improve this question














I am using jquery file upload to upload the files to the server . I want to restrict the user to upload maximum 6 files . I search the wiki jquery file upload but didnt find the parameter for it . Is there any way that i can restrict the user on number of uplaods







jquery jquery-file-upload






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Apr 15 '13 at 8:54









UahmedUahmed

99641935




99641935












  • which jquery plugin you are using? generally inside callback function it will hold those files in some sort of json array whose size you can put in if() clause

    – Abhishek K
    Apr 15 '13 at 9:07











  • A why not working version: stackoverflow.com/questions/21347805/…

    – Ciro Santilli 新疆改造中心 六四事件 法轮功
    Nov 8 '14 at 9:33

















  • which jquery plugin you are using? generally inside callback function it will hold those files in some sort of json array whose size you can put in if() clause

    – Abhishek K
    Apr 15 '13 at 9:07











  • A why not working version: stackoverflow.com/questions/21347805/…

    – Ciro Santilli 新疆改造中心 六四事件 法轮功
    Nov 8 '14 at 9:33
















which jquery plugin you are using? generally inside callback function it will hold those files in some sort of json array whose size you can put in if() clause

– Abhishek K
Apr 15 '13 at 9:07





which jquery plugin you are using? generally inside callback function it will hold those files in some sort of json array whose size you can put in if() clause

– Abhishek K
Apr 15 '13 at 9:07













A why not working version: stackoverflow.com/questions/21347805/…

– Ciro Santilli 新疆改造中心 六四事件 法轮功
Nov 8 '14 at 9:33





A why not working version: stackoverflow.com/questions/21347805/…

– Ciro Santilli 新疆改造中心 六四事件 法轮功
Nov 8 '14 at 9:33












5 Answers
5






active

oldest

votes


















30














Use maxNumberOfFiles here is documentation :



$('#fileuploadbasic').fileupload(

maxNumberOfFiles: 6

);





share|improve this answer


















  • 1





    This does not work in my case. I can select more than 6 files and it also uploads all selected files.

    – basZero
    May 9 '17 at 13:50











  • I found that sometimes the browser caches the .js file. Try refreshing the actual .js page and see if the changes take effect then.

    – BSUK
    Nov 27 '17 at 14:23


















16














maxNumberOfFiles was not working for me so i did the following



$('#fileuploadbasic').fileupload(
change : function (e, data)
if(data.files.length>=5)
alert("Max 5 files are allowed")
return false;

,
maxFileSize: 20000000,
acceptFileTypes: /(.);





share|improve this answer


















  • 3





    Awesome, exactly what I needed.

    – Cesar Bielich
    Jun 2 '16 at 19:19






  • 3





    This is also not working for me.

    – rida mukhtar
    Dec 23 '16 at 13:33






  • 3





    I can't edit the answer for some reason, but if you replace the "change" handler by "submit", it will work. That did the trick for me and "change" wasn't working either :)

    – NaturalBornCamper
    Mar 16 '17 at 9:29











  • @naturalBornCamper above code is for the time when we select file. it check the file before submitting.

    – Muhammad Tahir
    Jun 4 '17 at 19:08


















1














You can limit the uploading files by the "Uploadhandler.php" file .change the "max_number_of_files" option. works for me. But it only validates when you upload the file.






share|improve this answer























  • This is valid. A lot of the settings are available client side (via js) and server side (via PHP). I found it useful to duplicate on both, so that the user gets client feedback before the file has been uploaded, but a more secure level of validation takes place on the server also.

    – BSUK
    Nov 27 '17 at 14:25











  • Just remember to have some place to show this limit. In my case 100 uploads worked and the others failed, with no error message, just "An error ocurred".

    – Marcelo Agimóvel
    Mar 19 '18 at 2:41


















0














You can try:



$('#fileuploadbasic').fileupload(
//.....
paramName: 'your_input_name',
add : function (e, data)
if(data.paramName != undefined) data.submit();

);





share|improve this answer






























    0














    If you are using the "Krajee" fileupload, then you will have to use



    $('#fileuploadbasic').fileinput(
    maxFileCount: 6
    );


    If set to 0, it means size allowed is unlimited. Defaults to 0.






    share|improve this answer






















      Your Answer






      StackExchange.ifUsing("editor", function ()
      StackExchange.using("externalEditor", function ()
      StackExchange.using("snippets", function ()
      StackExchange.snippets.init();
      );
      );
      , "code-snippets");

      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "1"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













      draft saved

      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f16011200%2fjquery-file-upload-restricting-number-of-files%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      5 Answers
      5






      active

      oldest

      votes








      5 Answers
      5






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      30














      Use maxNumberOfFiles here is documentation :



      $('#fileuploadbasic').fileupload(

      maxNumberOfFiles: 6

      );





      share|improve this answer


















      • 1





        This does not work in my case. I can select more than 6 files and it also uploads all selected files.

        – basZero
        May 9 '17 at 13:50











      • I found that sometimes the browser caches the .js file. Try refreshing the actual .js page and see if the changes take effect then.

        – BSUK
        Nov 27 '17 at 14:23















      30














      Use maxNumberOfFiles here is documentation :



      $('#fileuploadbasic').fileupload(

      maxNumberOfFiles: 6

      );





      share|improve this answer


















      • 1





        This does not work in my case. I can select more than 6 files and it also uploads all selected files.

        – basZero
        May 9 '17 at 13:50











      • I found that sometimes the browser caches the .js file. Try refreshing the actual .js page and see if the changes take effect then.

        – BSUK
        Nov 27 '17 at 14:23













      30












      30








      30







      Use maxNumberOfFiles here is documentation :



      $('#fileuploadbasic').fileupload(

      maxNumberOfFiles: 6

      );





      share|improve this answer













      Use maxNumberOfFiles here is documentation :



      $('#fileuploadbasic').fileupload(

      maxNumberOfFiles: 6

      );






      share|improve this answer












      share|improve this answer



      share|improve this answer










      answered Apr 15 '13 at 9:18









      Mohamed AliMohamed Ali

      1,4571116




      1,4571116







      • 1





        This does not work in my case. I can select more than 6 files and it also uploads all selected files.

        – basZero
        May 9 '17 at 13:50











      • I found that sometimes the browser caches the .js file. Try refreshing the actual .js page and see if the changes take effect then.

        – BSUK
        Nov 27 '17 at 14:23












      • 1





        This does not work in my case. I can select more than 6 files and it also uploads all selected files.

        – basZero
        May 9 '17 at 13:50











      • I found that sometimes the browser caches the .js file. Try refreshing the actual .js page and see if the changes take effect then.

        – BSUK
        Nov 27 '17 at 14:23







      1




      1





      This does not work in my case. I can select more than 6 files and it also uploads all selected files.

      – basZero
      May 9 '17 at 13:50





      This does not work in my case. I can select more than 6 files and it also uploads all selected files.

      – basZero
      May 9 '17 at 13:50













      I found that sometimes the browser caches the .js file. Try refreshing the actual .js page and see if the changes take effect then.

      – BSUK
      Nov 27 '17 at 14:23





      I found that sometimes the browser caches the .js file. Try refreshing the actual .js page and see if the changes take effect then.

      – BSUK
      Nov 27 '17 at 14:23













      16














      maxNumberOfFiles was not working for me so i did the following



      $('#fileuploadbasic').fileupload(
      change : function (e, data)
      if(data.files.length>=5)
      alert("Max 5 files are allowed")
      return false;

      ,
      maxFileSize: 20000000,
      acceptFileTypes: /(.);





      share|improve this answer


















      • 3





        Awesome, exactly what I needed.

        – Cesar Bielich
        Jun 2 '16 at 19:19






      • 3





        This is also not working for me.

        – rida mukhtar
        Dec 23 '16 at 13:33






      • 3





        I can't edit the answer for some reason, but if you replace the "change" handler by "submit", it will work. That did the trick for me and "change" wasn't working either :)

        – NaturalBornCamper
        Mar 16 '17 at 9:29











      • @naturalBornCamper above code is for the time when we select file. it check the file before submitting.

        – Muhammad Tahir
        Jun 4 '17 at 19:08















      16














      maxNumberOfFiles was not working for me so i did the following



      $('#fileuploadbasic').fileupload(
      change : function (e, data)
      if(data.files.length>=5)
      alert("Max 5 files are allowed")
      return false;

      ,
      maxFileSize: 20000000,
      acceptFileTypes: /(.);





      share|improve this answer


















      • 3





        Awesome, exactly what I needed.

        – Cesar Bielich
        Jun 2 '16 at 19:19






      • 3





        This is also not working for me.

        – rida mukhtar
        Dec 23 '16 at 13:33






      • 3





        I can't edit the answer for some reason, but if you replace the "change" handler by "submit", it will work. That did the trick for me and "change" wasn't working either :)

        – NaturalBornCamper
        Mar 16 '17 at 9:29











      • @naturalBornCamper above code is for the time when we select file. it check the file before submitting.

        – Muhammad Tahir
        Jun 4 '17 at 19:08













      16












      16








      16







      maxNumberOfFiles was not working for me so i did the following



      $('#fileuploadbasic').fileupload(
      change : function (e, data)
      if(data.files.length>=5)
      alert("Max 5 files are allowed")
      return false;

      ,
      maxFileSize: 20000000,
      acceptFileTypes: /(.);





      share|improve this answer













      maxNumberOfFiles was not working for me so i did the following



      $('#fileuploadbasic').fileupload(
      change : function (e, data)
      if(data.files.length>=5)
      alert("Max 5 files are allowed")
      return false;

      ,
      maxFileSize: 20000000,
      acceptFileTypes: /(.);






      share|improve this answer












      share|improve this answer



      share|improve this answer










      answered May 14 '15 at 11:52









      Muhammad TahirMuhammad Tahir

      1,2621519




      1,2621519







      • 3





        Awesome, exactly what I needed.

        – Cesar Bielich
        Jun 2 '16 at 19:19






      • 3





        This is also not working for me.

        – rida mukhtar
        Dec 23 '16 at 13:33






      • 3





        I can't edit the answer for some reason, but if you replace the "change" handler by "submit", it will work. That did the trick for me and "change" wasn't working either :)

        – NaturalBornCamper
        Mar 16 '17 at 9:29











      • @naturalBornCamper above code is for the time when we select file. it check the file before submitting.

        – Muhammad Tahir
        Jun 4 '17 at 19:08












      • 3





        Awesome, exactly what I needed.

        – Cesar Bielich
        Jun 2 '16 at 19:19






      • 3





        This is also not working for me.

        – rida mukhtar
        Dec 23 '16 at 13:33






      • 3





        I can't edit the answer for some reason, but if you replace the "change" handler by "submit", it will work. That did the trick for me and "change" wasn't working either :)

        – NaturalBornCamper
        Mar 16 '17 at 9:29











      • @naturalBornCamper above code is for the time when we select file. it check the file before submitting.

        – Muhammad Tahir
        Jun 4 '17 at 19:08







      3




      3





      Awesome, exactly what I needed.

      – Cesar Bielich
      Jun 2 '16 at 19:19





      Awesome, exactly what I needed.

      – Cesar Bielich
      Jun 2 '16 at 19:19




      3




      3





      This is also not working for me.

      – rida mukhtar
      Dec 23 '16 at 13:33





      This is also not working for me.

      – rida mukhtar
      Dec 23 '16 at 13:33




      3




      3





      I can't edit the answer for some reason, but if you replace the "change" handler by "submit", it will work. That did the trick for me and "change" wasn't working either :)

      – NaturalBornCamper
      Mar 16 '17 at 9:29





      I can't edit the answer for some reason, but if you replace the "change" handler by "submit", it will work. That did the trick for me and "change" wasn't working either :)

      – NaturalBornCamper
      Mar 16 '17 at 9:29













      @naturalBornCamper above code is for the time when we select file. it check the file before submitting.

      – Muhammad Tahir
      Jun 4 '17 at 19:08





      @naturalBornCamper above code is for the time when we select file. it check the file before submitting.

      – Muhammad Tahir
      Jun 4 '17 at 19:08











      1














      You can limit the uploading files by the "Uploadhandler.php" file .change the "max_number_of_files" option. works for me. But it only validates when you upload the file.






      share|improve this answer























      • This is valid. A lot of the settings are available client side (via js) and server side (via PHP). I found it useful to duplicate on both, so that the user gets client feedback before the file has been uploaded, but a more secure level of validation takes place on the server also.

        – BSUK
        Nov 27 '17 at 14:25











      • Just remember to have some place to show this limit. In my case 100 uploads worked and the others failed, with no error message, just "An error ocurred".

        – Marcelo Agimóvel
        Mar 19 '18 at 2:41















      1














      You can limit the uploading files by the "Uploadhandler.php" file .change the "max_number_of_files" option. works for me. But it only validates when you upload the file.






      share|improve this answer























      • This is valid. A lot of the settings are available client side (via js) and server side (via PHP). I found it useful to duplicate on both, so that the user gets client feedback before the file has been uploaded, but a more secure level of validation takes place on the server also.

        – BSUK
        Nov 27 '17 at 14:25











      • Just remember to have some place to show this limit. In my case 100 uploads worked and the others failed, with no error message, just "An error ocurred".

        – Marcelo Agimóvel
        Mar 19 '18 at 2:41













      1












      1








      1







      You can limit the uploading files by the "Uploadhandler.php" file .change the "max_number_of_files" option. works for me. But it only validates when you upload the file.






      share|improve this answer













      You can limit the uploading files by the "Uploadhandler.php" file .change the "max_number_of_files" option. works for me. But it only validates when you upload the file.







      share|improve this answer












      share|improve this answer



      share|improve this answer










      answered Jul 1 '16 at 10:54









      HemanthaHemantha

      19317




      19317












      • This is valid. A lot of the settings are available client side (via js) and server side (via PHP). I found it useful to duplicate on both, so that the user gets client feedback before the file has been uploaded, but a more secure level of validation takes place on the server also.

        – BSUK
        Nov 27 '17 at 14:25











      • Just remember to have some place to show this limit. In my case 100 uploads worked and the others failed, with no error message, just "An error ocurred".

        – Marcelo Agimóvel
        Mar 19 '18 at 2:41

















      • This is valid. A lot of the settings are available client side (via js) and server side (via PHP). I found it useful to duplicate on both, so that the user gets client feedback before the file has been uploaded, but a more secure level of validation takes place on the server also.

        – BSUK
        Nov 27 '17 at 14:25











      • Just remember to have some place to show this limit. In my case 100 uploads worked and the others failed, with no error message, just "An error ocurred".

        – Marcelo Agimóvel
        Mar 19 '18 at 2:41
















      This is valid. A lot of the settings are available client side (via js) and server side (via PHP). I found it useful to duplicate on both, so that the user gets client feedback before the file has been uploaded, but a more secure level of validation takes place on the server also.

      – BSUK
      Nov 27 '17 at 14:25





      This is valid. A lot of the settings are available client side (via js) and server side (via PHP). I found it useful to duplicate on both, so that the user gets client feedback before the file has been uploaded, but a more secure level of validation takes place on the server also.

      – BSUK
      Nov 27 '17 at 14:25













      Just remember to have some place to show this limit. In my case 100 uploads worked and the others failed, with no error message, just "An error ocurred".

      – Marcelo Agimóvel
      Mar 19 '18 at 2:41





      Just remember to have some place to show this limit. In my case 100 uploads worked and the others failed, with no error message, just "An error ocurred".

      – Marcelo Agimóvel
      Mar 19 '18 at 2:41











      0














      You can try:



      $('#fileuploadbasic').fileupload(
      //.....
      paramName: 'your_input_name',
      add : function (e, data)
      if(data.paramName != undefined) data.submit();

      );





      share|improve this answer



























        0














        You can try:



        $('#fileuploadbasic').fileupload(
        //.....
        paramName: 'your_input_name',
        add : function (e, data)
        if(data.paramName != undefined) data.submit();

        );





        share|improve this answer

























          0












          0








          0







          You can try:



          $('#fileuploadbasic').fileupload(
          //.....
          paramName: 'your_input_name',
          add : function (e, data)
          if(data.paramName != undefined) data.submit();

          );





          share|improve this answer













          You can try:



          $('#fileuploadbasic').fileupload(
          //.....
          paramName: 'your_input_name',
          add : function (e, data)
          if(data.paramName != undefined) data.submit();

          );






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jul 14 '16 at 8:58









          ArtipixelArtipixel

          793716




          793716





















              0














              If you are using the "Krajee" fileupload, then you will have to use



              $('#fileuploadbasic').fileinput(
              maxFileCount: 6
              );


              If set to 0, it means size allowed is unlimited. Defaults to 0.






              share|improve this answer



























                0














                If you are using the "Krajee" fileupload, then you will have to use



                $('#fileuploadbasic').fileinput(
                maxFileCount: 6
                );


                If set to 0, it means size allowed is unlimited. Defaults to 0.






                share|improve this answer

























                  0












                  0








                  0







                  If you are using the "Krajee" fileupload, then you will have to use



                  $('#fileuploadbasic').fileinput(
                  maxFileCount: 6
                  );


                  If set to 0, it means size allowed is unlimited. Defaults to 0.






                  share|improve this answer













                  If you are using the "Krajee" fileupload, then you will have to use



                  $('#fileuploadbasic').fileinput(
                  maxFileCount: 6
                  );


                  If set to 0, it means size allowed is unlimited. Defaults to 0.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Dec 23 '17 at 13:10









                  TheCodeLordTheCodeLord

                  429511




                  429511



























                      draft saved

                      draft discarded
















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f16011200%2fjquery-file-upload-restricting-number-of-files%23new-answer', 'question_page');

                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      這個網誌中的熱門文章

                      How to read a connectionString WITH PROVIDER in .NET Core?

                      In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

                      Museum of Modern and Contemporary Art of Trento and Rovereto