How can PHP developers optimize file naming conventions to ensure unique file names in a file upload script?

To ensure unique file names in a file upload script, PHP developers can optimize file naming conventions by appending a timestamp or a unique identifier to the file name. This helps prevent overwriting existing files with the same name and ensures each uploaded file has a distinct name.

// Generate a unique file name by appending a timestamp
$timestamp = time();
$unique_filename = $timestamp . '_' . $_FILES['file']['name'];

// Move the uploaded file to a specific directory with the unique file name
move_uploaded_file($_FILES['file']['tmp_name'], 'uploads/' . $unique_filename);