Removing a File in PHP

Q

How To Remove a File in PHP?

✍: 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.

 

Copying a File in PHP

Removing an Empty Directory in PHP

Working with Directories and Files in PHP

⇑⇑ PHP Tutorials

2016-11-20, 1726🔥, 0💬