Summernote How To Delete Images Uploaded To A Folder

View File

Create a view.php file and put this in it. This will display the details of one entry with the option to delete it.

<?php include_once('header.php'); ?>
<div class="container-fluid">
  <h1>Entires</h1>
<?php 
$ct=1;
$theid= $_GET['p'] ?? 'Not Set';
$result = $con->query("SELECT * FROM entry WHERE id='$theid'") ;
while ($row = $result->fetch_assoc()) {
  echo '  <div class="row">
    <div class="col-sm-9">
      <p>'.$row['entries'].'</p>
    </div>
  <div class="col-sm-4">
  <form>
  <input id="entry" type="hidden" value="'.$row['id'].'">
      <button id="delete" class="btn btn-lg btn-danger">Delete</button>
  </form>
  <div id="display"></div>
    </div>
  </div>
';
$ct++;
}
?>
</div>
<style>.row{border:solid #000 1px;}</style>
<script>
$(document).ready(function(){
$("#delete").click(function(){
var entry = $("#entry").val();
var dataString = 'entry1='+ entry;
if(entry=='')
{
$("#display").html("Please Fill All Fields");
}
else
{
$.ajax({
type: "POST",
url: "processor.php",
data: dataString,
cache: false,
success: function(result){
$("#display").html(result);
}
});
}
return false;
});
});
</script>
<?php include_once('footer.php'); ?>

Processor File

Now you will need the processor.php file to remove all the images from the folder that were contained in your post. Here is the script.

<?php include_once('config.php'); 
$entry1=$_POST['entry1'];
$result = $con->query("SELECT * FROM entry WHERE id='$entry1' LIMIT 1") ;
while ($row = $result->fetch_assoc()) {
  $html = $row['entries'];
}
//get number of images
$pattern = '/<img[^>]*src=([\'"])(?<src>.+?)\1[^>]*>/i';
$numberofimages = preg_match_all($pattern, $html);
//get image paths from html
$get_Img_Src = '/<img[^>]*src=([\'"])(?<src>.+?)\1[^>]*>/i'; //get img src path only...
//$cunn=preg_match_all($get_Img_Src, $html, $result); 
preg_match_all($get_Img_Src, $html, $result); 
//delete images
for($var=0; $var < $numberofimages; $var++){
unlink($result['src'][$var]);
}
mysqli_query($con,"DELETE FROM entry WHERE id='$entry1'");
echo '<div class="alert alert-success">The entry and all of the images have been deleted</div>';
  echo '<script>window.location.replace("entry.php");</script>';
$con->close();
?>

I added some extra goodies if you want to download this file instantly. I only ask for a small donation of $5 for the time it took me to create it.




Only cool people share!

Summernote How To Delete Images Uploaded To A Folder was last modified: February 25th, 2023 by Maximus Mccullough
Summary
Summernote How To Delete Images Uploaded To A Folder
Article Name
Summernote How To Delete Images Uploaded To A Folder
Description
In Summernote you want to be able to delete your images in your directory or folder at times. As far as I can see, this is the only tutorial out there on this, so I decided to do it.
Author
Publisher
A1WEBSITEPRO LLC
Logo
Summernote How To Delete Images Uploaded To A Folder

Pages:Previous 1 2 3 4

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.