How can PDFs be assigned unique IDs during upload in PHP?

To assign unique IDs to PDFs during upload in PHP, we can use functions like uniqid() to generate a unique identifier for each file. This unique ID can then be appended to the filename before saving it to the server. This ensures that each PDF file uploaded will have a distinct identifier.

// Generate a unique ID for the PDF file
$uniqueID = uniqid();

// Get the original filename of the uploaded PDF
$filename = $_FILES['pdf_file']['name'];

// Append the unique ID to the filename
$newFilename = $uniqueID . '_' . $filename;

// Move the uploaded PDF file to a specified directory with the new filename
move_uploaded_file($_FILES['pdf_file']['tmp_name'], 'uploads/' . $newFilename);