Hi,
I want to delete my image file. I use routing system in my project. It consists of the controller and method (function) name and the data is passed. For example:
"http://localhost/MyProject/public/admin/index"
In the code above, admin is controller name and index is the method name. I use this system to carry file information to delete.php.
<a class="dropdown-item" href="<?php echo $root ?>/public/delete/index/<?php echo $myrow['thumb'] ?>">Delete</a>
delete.php:
<?php
class Delete{
public function index($file){
$this->DeleteFile($file);
}
public function DeleteFile($file){
if(file_exists("/MyProject/public/assets/img/$file")){
unlink("/MyProject/public/assets/img/$file");
unlink("/MyProject/public/assets/uploadThumb/$file");
}else{
echo "File not exists.";
}
}
}
The problem is that the file cannot be deleted and says that the file not exists. My real file address is:
C:\xampp\htdocs\MyProject\public\assets\img\97c584dbaj.jpg
How can I solve this problem?
What I have tried:
<?php
class Delete{
public function index($file){
$this->DeleteFile($file);
}
public function DeleteFile($file){
if(file_exists("/MyProject/public/assets/img/$file")){
unlink("/MyProject/public/assets/img/$file");
unlink("/MyProject/public/assets/uploadThumb/$file");
}else{
echo "File not exists.";
}
}
}