How can timestamps be used in PHP to prevent file name conflicts during uploads?

When multiple users upload files simultaneously, there is a possibility of file name conflicts if they upload files with the same name. One way to prevent this is by using timestamps in the file names. By appending a timestamp to the file name before uploading, each file will have a unique name based on the time it was uploaded, thus avoiding conflicts.

// Generate a unique file name using timestamp
$timestamp = time();
$file_name = $timestamp . '_' . $_FILES['file']['name'];

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