PHP Unlink doesn’t fully delete file but converts it to a 0kb file [duplicate]

  php

I can see that the image I am trying to delete using unlink in PHP doesn’t get deleted but I can see the same file, corrupted this time and its size is 0kb

My code:

$file_pointer = fopen($onoma, 'w');  

// Use unlink() function to delete a file  
if (!unlink($file_pointer)) {  
    echo ("$file_pointer cannot be deleted due to an error");  
}  
else {  
    echo ("$file_pointer has been deleted");  
}  

Plus, the error I am getting is given below:

Warning: unlink() expects parameter 1 to be a valid path, resource given in C:xampphtdocs\delete_image.php on line 80
The image has been deleted.

Source: Ask PHP

LEAVE A COMMENT