javascript - Count the number of images selected with input=file -


Is there a way in PHP to show the number of files selected from an "input = file" inside the input? something like that.

Enter image details here

I saw only code which Print the number in a label outside the input, such as (from this question)

  $ ('input [type = file]'). Change (function () {fileCount = this files.length; $ (this) .prev () .text (filecount + 'selected');})  

but I can not understand How am I able to put in the input ... inside the "value" can be?

This is my input code

  & lt; Div id = "file-ins-immagini" & gt; & Lt; Div class = "at-form-in" & gt; AggiGi Iginese & lt; / Div & gt; & Lt; Input type = "file" name = "file-input []" id = "file-input" value = "" class = "file" multiple & gt; & Lt; / Div & gt;  

Thanks!

It is very easy to use plain javascript, or jQuery:

  / * Input files calculation * / $ ("body") ("Change", function () {var numFiles = $ ("input", [0] .files.length; $ ('.phpfile'). Adclass ('active'); // optional for optional CSS}};  

The above code creates a function that calculates whatever you choose from the form button. With jQuery Styling Elements (CSS / Mouseover Effects) Allows a little more creativity, but is not necessary

 Code-js lang-js prettyprint-override ">  / * Input files calculation * / $ (" body "). [0] .files.length; $ ('.php files') AddClass ('Active');}) / / mouseover effects * / $ ('.php files'). Mouseover (function ($ (this) .addClass ('over');}). Mouseout (function () { $ (This) .removeClass ('over');});  
  & lt; Script src = "https://ajax.googleapis.com/ajax/libs/JQuery/1.11.1/jquery.min.js" & gt; & Lt; / Script & gt; & Lt; Div id = "wrapper" & gt; & Lt; Div class = "browseTitle" & gt; Imaginee aligate & lt; / Div & gt; & Lt; Div class = "browsefiles" & gt; & Lt; Form enctype = "multipart / form-data" class = "button" & gt; & Lt; Input type = "file" name = "upload file []" multiple = "multiple" /> & Lt; / Form & gt; & Lt; / Div & gt; & Lt; / Div & gt;  


Comments