title: Deleting image problem with unlink function
body: <p>I created this method to unlink when I update the image but it doesn't work with if not empty if I say empty it deletes. it is so strange I tried but didn't work. I tried this without oop it works in another application. I changed it for it and I checked google but no solution till now. someone used is_uploaded_file on here for the solution but it doesn't work too.</p>
  
  <pre><code>    public $tmp_path;
      public $upload_directory = "images"; 
  
  public function picture_path(){
        return $this-&gt;upload_directory.DS.$this-&gt;filename;
      }
        public function set_file($file) { 
  
            if(empty($file) || !$file || !is_array($file)) {
              $this-&gt;errors[] = "There was no file uploaded here";
              return false;
            }elseif($file['error'] !=0) {
              $this-&gt;errors[] = $this-&gt;upload_errors_array[$file['error']];
              return false;
            } else {
              $this-&gt;filename = basename($file['name']);
              $this-&gt;filename = preg_replace('#[^a-z.0-9]#i', '', $this-&gt;filename); 
              $kaboom = explode(".", $this-&gt;filename); // Split file name into an array using the dot
              $fileExt = end($kaboom); // Now target the last array element to get the file extension
              $this-&gt;filename = time().rand().".".$fileExt;
              $this-&gt;tmp_path = $file['tmp_name'];
              $this-&gt;type     = $file['type'];
              $this-&gt;size     = $file['size'];
            }
          }
  
           public function getordelimage(){
                    static::find_by_id($this-&gt;id);
                    $target_path = SITE_ROOT.DS. 'admin' . DS . $this-&gt;picture_path();
                    if(empty($this-&gt;tmp_path)) { 
                        $this-&gt;filename;
                        $this-&gt;type;
                        $this-&gt;size;      
                    } elseif (!empty($this-&gt;tmp_path)) {
                      return unlink($target_path) ? true : false;
                    } else {
                      return false;
                    }
                  }
      public function move_image(){
            $target_path = SITE_ROOT.DS. 'admin' . DS . $this-&gt;upload_directory . DS . $this-&gt;filename;
            return move_uploaded_file($this-&gt;tmp_path, $target_path);
          }
  
          public function delete_photo(){
            if ($this-&gt;delete()) {
              $target_path = SITE_ROOT.DS. 'admin' . DS . $this-&gt;picture_path();
              return unlink($target_path) ? true : false;
            } else {
              return false;
            }
          }
  </code></pre>
  
  <p>my edit page:</p>
  
  <pre><code>if (empty($_GET['id'])) {
      redirect("photos.php");
  } else {
      $photo = Photo::find_by_id($_GET['id']);
      }
  if (isset($_POST['update'])) {
      // $photo = Photo::find_by_id($_GET['id']);
      if ($photo) {
          $photo-&gt;title = filter_var($_POST['title'], FILTER_SANITIZE_STRING);
          $photo-&gt;caption = filter_var($_POST['caption'], FILTER_SANITIZE_STRING);
          $photo-&gt;alternate_text = filter_var($_POST['alternate_text'], FILTER_SANITIZE_STRING);
          $photo-&gt;description = filter_var($_POST['description'], FILTER_SANITIZE_STRING);
  
  
          $photo-&gt;set_file($_FILES['filename']);
          $photo-&gt;getordelimage();
          $photo-&gt;move_image();
  
          // if ($photo-&gt;set_file($_FILES['file'])) {
               $params = [$photo-&gt;title, $photo-&gt;description, $photo-&gt;caption,$photo-&gt;alternate_text,
             $photo-&gt;filename, $photo-&gt;type, $photo-&gt;size,
              ];
          // } else {
          //     $params = [$photo-&gt;title, $photo-&gt;description, $photo-&gt;caption,$photo-&gt;alternate_text];
          // }
  
          $photo-&gt;save($params);
          $session-&gt;message("The {$photo-&gt;filename} has been updated");
          redirect("edit_photo.php?id=$photo-&gt;id");
      }
  }
  </code></pre>