tags:

views:

40

answers:

1

I'm trying to delete the current image that is already set on the server when a user submits a new image to the server, but I don't know how to do add this to my current code can some one please help me?

Here is my PHP & MySQL code.

if(isset($_FILES["thumb"]["name"])) { 

  if (file_exists("/images/" . $_FILES["thumb"]["name"])) {

    $thumb != $_FILES["thumb"]["name"];

  } else if($_FILES["thumb"]["name"] == TRUE) {

    move_uploaded_file($_FILES["thumb"]["tmp_name"],
      "/images/" . mysqli_real_escape_string($mysqli, htmlentities(strip_tags(basename($_FILES["thumb"]["name"])))));
    $thumb = mysqli_real_escape_string($mysqli, htmlentities(strip_tags(basename($_FILES["thumb"]["name"]))));

  } 

  if($thumb == TRUE) {
    //create thumb code here...
  }

}
A: 

use below code

$filename=$_FILES['thumb']['name'];  
$oldimage='23.png'

if ((file_exists("thumb/".$oldimage))  && ($oldimage!=$filename)) {
    unset($oldimage);
  }

replace your if condition with above code inside if(isset(...){ 'here'

}

diEcho
Where do I place it in my code?
pc-wiki
i updated my answer, and use single quote inside `$_FILE['']['']`
diEcho
why u using `$thumb!=$_FILE['thumb']['name']` ? i think you shoud use `==` instead of `!=`
diEcho
This code didn't work for me but thanks for your time and help.
pc-wiki
It just wont delete the image its replacing.
pc-wiki
replacing means it's deleting...what u want more? and what is in `$thumb` ?OOPS! i m sorry u have to unset `$thumb` not `$filename`
diEcho
everything is okay its just the code.
pc-wiki
I want the image to delete the other image with a different name its replacing for example `thumbs/23.jpg` should be replaced by `thumbs/24.png`
pc-wiki
i updated the code. see that
diEcho