What are the risks of allowing files with duplicate names to be uploaded in PHP applications?

Allowing files with duplicate names to be uploaded in PHP applications can lead to potential conflicts and confusion when managing files. To prevent this issue, you can append a unique identifier to the file name before uploading it to the server. This ensures that each file has a distinct name and avoids overwriting existing files.

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

// Append the unique identifier to the file name
$file_name = $unique_id . '_' . $_FILES['file']['name'];

// Upload the file with the unique name
move_uploaded_file($_FILES['file']['tmp_name'], 'uploads/' . $file_name);