PHP File delete using unlink function
We can check the path by using file_exists function to know if file is available for deletion. Here $path is the relative path of the file calculated from the script execution. Here is an example of deleting file by using relative path
We have used if condition to check whether the file delete command is successful or not. But the command below will not work.
The warning message will say unlink() [function.unlink]: HTTP does not allow unlinking.
We can suppress the warning message by adding a @ symbol before the unlink command .
Based on the success of the file delete command we can further execute our code by using if else code block.
Here we are deleting one file only. We can also delete all the files of a directory or selected files by using PHP.
Deleting database record linked to file.
The name of the file is stored in a table record. While deleting such file , first record is to be deleted ( if required ) and on success of deletion the respective file is to be deleted.
Subscribe to our YouTube Channel here
This article is written by plus2net.com team. https://www.plus2net.com