Hier ein kleines Video wie ich es meine bzw wie mein Problem aussieht:
https://www.youtube.com/watch?v=MNxNpTBzIkw&feature
Mein Code in HTML sieht so aus:
<div class="add-comment">
<div class="area">
<form id="form-<?= $rowsafe['p_id']; ?>" value="2" class="formarea" enctype="multipart/form-data" method="POST">
<textarea class="send_comment send_comment-<?= $rowsafe['p_id']; ?>" name="text" id="send_comment_by_id" onPaste="" autocomplete="off" autocorrect="off" placeholder="Kommentieren... (Mit Enter absenden)" onkeypress="return enter(event);" data-id="<?= $rowsafe['p_id']; ?>" style="height:46px;"></textarea>
<input type="hidden" name="id" class="comment_send_id" value="<?= $rowsafe['p_id']; ?>">
</div>
<div class="comment-photos">
<ul>
<li>
<input type="file" onchange="changeEventHandler(this);" data-id="<?= $rowsafe['p_id']; ?>" name="datei" id="file" class="inputfile">
<label for="file" value="<?= $rowsafe['p_id']; ?>">
<img src="https://png.icons8.com/color/50/000000/google-images.png" value="<?= $rowsafe['p_id']; ?>">
</label>
</li>
</ul>
</div>
</form>
</div>
In Javascript:
function changeEventHandler(ele) {
var img = event.target.value;
var value = ele.dataset.id;
if(img != '') {
$.ajax({
type: 'POST',
url: 'beicht_comments_datas/photo.php',
data: new FormData($($('#form-'+value))[0]),
async: false,
cache: false,
contentType: false,
processData: false,
success: function(data) {
$('.output-content').css('display', 'block');
$('.output-photo-'+value).html(data);
}
})
} else {
$('.output-content-'+value).css('display', 'none');
}
}