How to remove image from server directory?

Discussion in 'PHP' started by falconlink, Aug 29, 2011.

  1. #1
    Hi

    I have a developed a script. I can add, remove images though php form and images successfully uploading into remote server directory and database keep the records. If I remove any record, it works and my question is there any code to remove the exact image file from server while I remove the database record?

    I trust, I could make you understand the fact.
     
    falconlink, Aug 29, 2011 IP
  2. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #2
    
    
    $image_file = "images/sample_image.png"; // you'll need to create something here to write the image name / it should be same url listed in your database
      if (file_exists($image_file)) 
        { 
            unlink("$image_file"); // unlink() deletes the file from your server
        }
    
    
    PHP:
     
    MyVodaFone, Aug 29, 2011 IP
  3. ROOFIS

    ROOFIS Well-Known Member

    Messages:
    1,234
    Likes Received:
    30
    Best Answers:
    5
    Trophy Points:
    120
    #3
    code example here:
    http://www.w3schools.com/php/php_mysql_delete.asp
    just merge this with MyVodaFone's code above.
     
    ROOFIS, Aug 29, 2011 IP