What are some potential pitfalls to avoid when creating a script to upload and number files in PHP?

One potential pitfall to avoid when creating a script to upload and number files in PHP is not properly handling file uploads and ensuring that the file names are unique to prevent overwriting existing files. To solve this issue, you can use functions like `uniqid()` to generate a unique identifier for each file uploaded.

// Check if file was uploaded successfully
if ($_FILES['file']['error'] === UPLOAD_ERR_OK) {
    $file_name = uniqid() . '_' . $_FILES['file']['name'];
    $upload_path = 'uploads/' . $file_name;
    
    // Move uploaded file to designated directory
    if (move_uploaded_file($_FILES['file']['tmp_name'], $upload_path)) {
        echo 'File uploaded successfully.';
    } else {
        echo 'Failed to move file.';
    }
} else {
    echo 'Error uploading file.';
}