Home > Articles > Programming > PHP

This chapter is from the book

Creating and Deleting Files

If a file does not yet exist, you can create one with the touch() function. Given a string representing a file path, touch() attempts to create an empty file of that name. If the file already exists, the contents are not disturbed, but the modification date is updated to the time at which the function executed.

touch("myfile.txt");

You can remove an existing file with the unlink() function. Once again, unlink() accepts a file path:

unlink("myfile.txt");

All functions that create, delete, read, write, or modify files on Unix systems require that the correct file or directory permissions are set.

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.