How To Remove a File


How To Remove a File? - PHP Script Tips - Working with Directoris and Files



If you want to remove an existing file, you can use the unlink() function. Here is a PHP script example on how to use unlink():

if (file_exists("/temp/todo.txt")) {
  print("File removed.\n");
} else {
  print("File does not exist.\n");

This script will print:

File removed.

If you run this script again, it will print:

File does not exist.

2007-04-23, 4731👍, 0💬