Creating and Deleting Files

If a file does not yet exist, you can create it 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 aren't 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. As did the touch() function, unlink() accepts a file path:

unlink("myfile.txt");

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

Get Sams Teach Yourself PHP, MySQL® and Apache All in One now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.