What best practices should be followed when handling file manipulation tasks in PHP, especially involving timestamps in file names?

When handling file manipulation tasks in PHP, especially when dealing with timestamps in file names, it is important to ensure proper formatting to avoid issues with file creation, modification, and retrieval. One best practice is to use the `date()` function to generate a timestamp in a consistent format that can be easily sorted and identified. Additionally, it is recommended to sanitize user input to prevent any potential security vulnerabilities.

// Example of generating a timestamp for file names
$timestamp = date('Y-m-d_H-i-s');

// Example of sanitizing user input for file names
$userInput = $_POST['filename'];
$sanitizedFileName = preg_replace("/[^a-zA-Z0-9-_\.]/", "", $userInput);