Reputation: 425
UPDATED
How i can hold added files by input field?
I created this script: http://jsfiddle.net/dyzg9qa8/1/
jQuery(document).ready(function() {
$('input').on('change', function(event) {
var img = this.files;
var show = '.s_' + $(this).attr("class");
$.each(img, function(index, f) {
var reader = new FileReader();
reader.onload = function(e){
$('<img src="' + e.target.result + '" width="450">').appendTo(show);
}
reader.readAsDataURL(f);
});
});
});
and html:
<form method="post" enctype="multipart/form-data">
<label for="images">Multiple Images</label>
<input type="file" class="img1" name="img[]" multiple accept="image/*">
<div class="s_img1"></div>
<hr>
<label for="images">Multiple Images</label>
<input type="file" class="img2" name="img[]" multiple accept="image/*">
<div class="s_img2"></div>
<input type="submit" value="Send">
</form>
when for eg. I add two images to the input will be displayed below, and as I click again on the input and I will add one more picture of this will be added to these two below. So now I have 3 pictures below.
but when I type in php "print_r" in the form displays only the last value of the input. in $_FILES only is submit last value of input. I want send all values added before, how to do this ? :)
regards!
Upvotes: 0
Views: 67
Reputation: 137
the name=""
attribute is what defines the variable name in PHP.
So having two tags with name="img"
will make the 2nd overwrite the first.
You'll need to do one of the following:
name="img[]"
This makes the name img
an array and when PHP receives it, it can foreach
through img
or you can do name="img1"
and name="img2"
for PHP to pick them up separately.
You should also be using the $_FILES['img']
variable to access files (including images) uploaded to the server.
Upvotes: 2