How To Remove a File

Q

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

✍: FYIcenter.com

A

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():

<?php
if (file_exists("/temp/todo.txt")) {
  unlink("/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, 4732👍, 0💬