How can the issue of file renaming and numbering be efficiently addressed in PHP file uploads?

Issue: The problem of file renaming and numbering arises when multiple users upload files with the same name, leading to potential conflicts and overwriting of existing files. To address this efficiently, we can append a unique identifier to the file name during the upload process, ensuring each file has a distinct name.

// Generate a unique identifier for the file name
$unique_id = uniqid();

// Get the original file name
$original_name = $_FILES['file']['name'];

// Extract the file extension
$file_extension = pathinfo($original_name, PATHINFO_EXTENSION);

// Construct the new file name with the unique identifier
$new_file_name = $unique_id . '.' . $file_extension;

// Move the uploaded file to the desired directory with the new name
move_uploaded_file($_FILES['file']['tmp_name'], 'uploads/' . $new_file_name);