What are the potential pitfalls of using md5(time()) for file naming in PHP?

Using md5(time()) for file naming in PHP can result in potential collisions if multiple files are created within the same second. To avoid this issue, you can append a unique identifier, such as a random string or a UUID, to the filename before hashing it with md5.

// Generate a unique identifier
$unique_id = uniqid();

// Create a filename using md5 hashing with a unique identifier
$filename = md5($unique_id . time()) . '.txt';

// Use the $filename for file naming