What is the purpose of the touch() function in PHP?
The touch() function in PHP is used to create a new file if it does not already exist, or update the last access and modification timestamps of an existing file. This function is commonly used when you need to ensure a file exists or update its timestamps without modifying its content.
// Example usage of touch() function to create or update file timestamps
$filename = 'example.txt';
// Create the file if it doesn't exist
if (!file_exists($filename)) {
touch($filename);
}
// Update the file timestamps
touch($filename);