-2

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?

Marty
  • 1
  • 1
  • See this similar question: http://stackoverflow.com/questions/15941592/php-multiple-file-array – kaaposc Jun 21 '15 at 20:53
  • So i should do something like this? its not working neither:/ $ghj = count($_FILES['files']['tmp_name']); – Marty Jun 21 '15 at 21:04

1 Answers1

0

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
  }
});
Community
  • 1
  • 1
Tim Hultstrand
  • 424
  • 2
  • 7