File Delete

☰ Menu Content


Now it's time to learn how to destroy (delete) files.

In PHP you delete files by calling the unlink function.

File Unlink

If you unlink a file, you are effectively causing the system to forget about it or delete it

Before you can delete (unlink) a file, you must first be sure that it is not open in your program.

Use the fclose function to close down an open file.

Now to delete a file "unlink" just needs to know the path and name of the file to delete it.

PHP Code:
$myFile = "testFile.txt";
unlink($myFile);

The testFile.txt should now be removed.

Unlink: Safety First

Remember that you can get messed up.

When you are performing the unlink function be sure that you are deleting the right file

Note
For more detail please see Php Manual at http://www.php.net

Php Tutorial Content (menu)