Asked 3 years ago
30 Jun 2021
Views 429
Mikel

Mikel posted

How to delete a file via PHP?

How to delete a file via PHP?
Mitul Dabhi

Mitul Dabhi
answered Aug 8 '21 00:00

unlink() function can be used to delete the file

unlink(file path) : it will delete the file for given file path.
unlink() returns True if file deleted successfully , returns False if file not deleted succesfully

unlink(string $filename, resource $context = ?):return bool
Deletes a file

Code example for unlink:

unlink('unwantedfile.php')

above code will be deleted unwantedfile.php in the same directory.
you can put relative or absolute path like full path
Post Answer