I have an array of images like {A:[img1,img2], B:[img1]}
.
I want to delete those array values that are any previewed images when clicking the delete button.
Each image has a separate delete button.
This is my code:
{"balcony":["1477990880.jpg","1477990923.jpg"],"apartment":["1477990905.jpg"]}
<?php if(isset($multi_images))
$newArray = array();
foreach($multi_images as $key => $value) {
for($i=0; $i<count($value); $i++) { ?>
<div id="filediv">
<img src="<?php echo SITE_PATH."/mb-images/delete_pic.png"; ?>" alt="" class="img-responsive" id="multiImagedelete" onclick="">
<img src="<?php echo SITE_PATH."/data/users/".$value[$i]; ?>" name="images[]" alt="" class="img-responsive" id="<?php echo $key.$i; ?>">
<?php array_push($newArray, $value[$i]);?>
{{ Form::label($key, $key, array('class' => 'label_field')) }}
</div>
<?php }} ?>
if you just want to remove them from the DOM :
$('#filediv img').click(function(){
$(this).remove(); // remove the image (from the dom)
});
Or : if you want to delete it from the DB
$('#filediv img').click(function(){
$.post('url-to-your-controller', DATA, function(){
alert('The file has been deleted from DB');
})
});
DATA will be for example the id of your image, that you will have set on your img tag :
<img src="..." data-img-id="The-id-dynamicly-set-here" />
and retrieve it in jquery :
$(this).data('img-id');