Jaynen Reibling
Jaynen Reibling

Reputation: 1

Using ImageSecure And I Cant Delete An Image Upload

I am using a image upload script called ImageSecure that I downloaded and setup. Everything works great except for when I go to delete an image. Nothing happends, no error messages, nothing. If I comment out the first "return $this->obj;" line i can delete the table row from the database, But the file unlink does not work and no file is deleted. Can anyone help?

I am calling the script with this... '$result = $img->deleteImage(35);' 35 is the id im using to test.

public function deleteImage($id){

        $this->stmt = $this->dbh->prepare("SELECT name, original_name, FROM ". DB_TABLE ." WHERE id=:id");
        
        $this->bind(':id', $id);
        
        try{
            $this->stmt->execute(); /////////////////////////////////////if I comment out this I can delete the file from the database but unlink still doesnt work.
            $result = $this->stmt->fetch(PDO::FETCH_ASSOC);
        }
        catch(PDOException $e){
            array_push($this->error, $e->getMessage());
            $this->obj->error = $this->error;
            return $this->obj;
        }

        unlink(F_PATH.'/'.$result['name']);

        $this->stmt = $this->dbh->prepare("DELETE FROM ". DB_TABLE ." WHERE id=:id");

        $this->bind(':id', $id);

        try{ 
            $this->stmt->execute();
        }
        catch(PDOException $e){
            array_push($this->error, $e->getMessage());
            $this->obj->error = $this->error;
            return $this->obj;
        }

        array_push($this->info, "File: ". $result['original_name'] ." succesfully deleted.");
        $this->obj->info = $this->info;
        return $this->obj;
    }

Upvotes: -2

Views: 39

Answers (0)

Related Questions