获取有关所选文件数量的信息

i've created some code

<input class="upload"  type="file" value="choose" name="files[]" multiple="multiple" required>
                    ';
    $ghj = count(files);
 
    echo '
    <input type="hidden" name="ghj"  value="'.$ghj.'">
<input type="submit" name="send" class="check-button" value="check">

and need really bad to know before submitting how many files was chosen. And it has to be in php variable... i tried everything i know and nothing is working. Could anybody help me?

</div>

If you need this information before submitting the form, you'd like to use Javascript instead of PHP.

According to another Stackoverflow thread, there is a way to get these files using Javascript/jQuery:

Example using jQuery:

var files = $(".upload").first().files;
var filesCount = files.length;

alert(filesCount);

However, you say you'll need this as an PHP variable. I don't really understand, since you'll need this information before the form submit.

Well, you can use AJAX for PHP to process the information if that's a solution for you:

http://api.jquery.com/jquery.post/

Example:

var files = $(".upload").first().files;
var filesCount = files.length;

$.ajax({
  type: "POST",
  url: 'URL_TO_PHP_SCRIPT',
  data: {
      count: filesCount
  }
});