Removing a File in PHP


How To Remove a File in PHP?



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.


Copying a File in PHP

Removing an Empty Directory in PHP

Working with Directories and Files in PHP

⇑⇑ PHP Tutorials

2016-11-20, 1553🔥, 0💬