1
need to count the number of input file elements, as they are created dynamically, with the click of a button
<input class="tf" type="file" name="pic[]" accept="image/*">
this is the line that is created dynamically, but I need to count the number of elements that were created, does not work with Count, as I can do?
this is my php code, with the variable paragraph already right.
<?php
$paragrafo = isset($_POST['paragrafo']) ? $_POST['paragrafo'] : '';
$foto = isset($_FILES['pic']) ? $_FILES['pic'] : '' ;
echo count($_POST['pic']);
if(count($paragrafo) > 0 && $paragrafo != ''){
foreach($paragrafo as $item){
echo $item .'<br>';
}
} else {
echo "Nenhum paragrafo foi adicionado!";
}
?>
This is a input file normally returns a simple array, for a single selected file, and returns a multi. when set Multiple. The point is ?
– Edilson
i want to count the number of inputs that were created in my html
– alexandre9865
Fields are generated via php ?
– Edilson
no, via jquery/javascript plugin
– alexandre9865
But the input of the kind file usually it is only one.
– Edilson
as you click the add image button, with id="add-img"
– alexandre9865
is that I will have to generate a pdf document, and this will have to have images and paragraphs, necessarily having to have the order that would be presented on the screen, among paragraphs and images...
– alexandre9865
I, not to have to think too much, would add in the JS function that adds the images one call to another function that increments a numerical value in a hidden field. every time you add vc would have the exact value of the fields in your DOM
– Renato Tavares