Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Jan 2007
    Posts
    42
    Thanks
    4
    Thanked 0 Times in 0 Posts

    delete image from folder

    Hi
    i was wondering if anyone can help me with a small problem im having? i have this script that will let users delete there messages from my database witch is working great and with each message they save they have to upload a image it will save the path of the image in the database and save the image to a folder is there anyway when they delete a message it will also delete the image in the folder by grabbing the path from the selected message there trying to delete? i have tried using unlink($image); but have no idea how to go about adding this thanks...
    my code:
    PHP Code:
    <?php
    $checkbox 
    $_POST['checkbox'];
    $delete    mysql_real_escape_string(strip_tags($_POST['delete']));
    $user       mysql_real_escape_string($_SESSION['id']);
    if(
    $delete){
    for(
    $i=0;$i<$count;$i++){
    $del_id $checkbox[$i];
    $sql "UPDATE messages SET
    WHERE id = '{$del_id}'
    And username = '{$user}'"
    ;
    mysql_query($sql$conn
    or die(
    'Error in query:<br>'$sql .'<br>'.mysql_error($conn).'<br>Time of Error: '.date("l F j, Y, G:i:s T"));
    }
    if(
    $result){
    echo 
    "<meta http-equiv=\"refresh\" content=\"0\">\n";
    }
    }
    mysql_close();
    ?>

  • #2
    Regular Coder
    Join Date
    Oct 2011
    Posts
    236
    Thanks
    11
    Thanked 5 Times in 5 Posts
    Quote Originally Posted by ycpc55 View Post
    Hi
    i was wondering if anyone can help me with a small problem im having? i have this script that will let users delete there messages from my database witch is working great and with each message they save they have to upload a image it will save the path of the image in the database and save the image to a folder is there anyway when they delete a message it will also delete the image in the folder by grabbing the path from the selected message there trying to delete? i have tried using unlink($image); but have no idea how to go about adding this thanks...
    my code:
    PHP Code:
    <?php
    $checkbox 
    $_POST['checkbox'];
    $delete    mysql_real_escape_string(strip_tags($_POST['delete']));
    $user       mysql_real_escape_string($_SESSION['id']);
    if(
    $delete){
    for(
    $i=0;$i<$count;$i++){
    $del_id $checkbox[$i];
    $sql "UPDATE messages SET
    WHERE id = '{$del_id}'
    And username = '{$user}'"
    ;
    mysql_query($sql$conn
    or die(
    'Error in query:<br>'$sql .'<br>'.mysql_error($conn).'<br>Time of Error: '.date("l F j, Y, G:i:s T"));
    }
    if(
    $result){
    echo 
    "<meta http-equiv=\"refresh\" content=\"0\">\n";
    }
    }
    mysql_close();
    ?>
    You need to get the image location from the database before deleting the database query and then it's just unlinking the image. Then you need to delete from database.

    So the order it needs is

    Fetch image path
    Delete database
    Delete file

    You can get the database queries by researching google if your not 100% sure


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •