How can collisions be handled when generating unique file names using hashes in PHP?

When generating unique file names using hashes in PHP, collisions can occur if two different inputs produce the same hash value. To handle collisions, one common approach is to append a unique identifier to the file name before hashing it to ensure uniqueness.

$input = "example_input";
$hash = sha1($input);
$unique_id = uniqid();
$unique_file_name = $hash . "_" . $unique_id;

echo $unique_file_name;