To delete a file in PHP, we can use the unlink()
function which deletes the file specified in the parameter passed to it. Here's an example:
main.php161 chars8 lines
In the code above, we first check if the file exists using file_exists()
function. If it exists, then we delete it using unlink()
function. If it doesn't exist, we display a message saying that the file was not found.
It's important to note that once the file is deleted, it cannot be recovered. Therefore, it is a good practice to add an extra layer of confirmation before performing this operation.
gistlibby LogSnag