Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Assign a random classname to the <code>&lt;input&gt;</code>s for example:</p> <pre><code>&lt;form action="" method="post" enctype="multipart/form-data"&gt; &lt;input type="file" name="file[]" class="fileuploadCounter"&gt; &lt;input type="file" name="file[]" class="fileuploadCounter"&gt; &lt;input type="file" name="file[]" class="fileuploadCounter"&gt; &lt;input type="file" name="file[]" class="fileuploadCounter"&gt; &lt;/form&gt; </code></pre> <p>After init, <code>$('.fileuploadCounter').length()</code> will return the amount of elements with that class, in this example, four. See the <a href="http://api.jquery.com/length/" rel="nofollow">jQuery documentation</a>.</p> <p><hr> <strong>Old answer underneath</strong></p> <p>Change the name on the <code>&lt;input&gt;</code> tags to <code>images[]</code>, and count <code>$_POST['images']</code> server side.</p> <p>Eg:</p> <pre><code>&lt;form action="" method="post" enctype="multipart/form-data"&gt; &lt;input type="file" name="file[]"&gt; &lt;input type="file" name="file[]"&gt; &lt;input type="file" name="file[]"&gt; &lt;input type="file" name="file[]"&gt; &lt;/form&gt; &lt;?php if($_SERVER['REQUEST_METHOD'] == "POST"){ if(isset($_FILES['file'])){ // Because we added [] in the name tag and they match names, $_FILES['file'] is now an array containing the images. if(count($_FILES['file']) &gt; 4){ // More than 4 files } else { // Less then four! foreach($_FILES['file'] as $file){ move_uploaded_file($file["file"]["tmp_name"], "uploads/" . $files["file"]["name"]); } } } } ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload