What are potential pitfalls to be aware of when handling file uploads in PHP, such as checking for warnings or notices during the process?

When handling file uploads in PHP, it is important to check for warnings or notices during the process to prevent potential security vulnerabilities or errors. One common pitfall is not properly validating the file type or size before processing the upload, which can lead to security risks like allowing malicious files to be uploaded. To avoid this, always validate the file type and size before moving the uploaded file to the destination folder.

if ($_FILES['file']['error'] === UPLOAD_ERR_OK) {
    $allowedTypes = ['image/jpeg', 'image/png'];
    $maxFileSize = 2 * 1024 * 1024; // 2 MB

    if (in_array($_FILES['file']['type'], $allowedTypes) && $_FILES['file']['size'] <= $maxFileSize) {
        // Process the file upload
        move_uploaded_file($_FILES['file']['tmp_name'], 'uploads/' . $_FILES['file']['name']);
        echo 'File uploaded successfully!';
    } else {
        echo 'Invalid file type or size.';
    }
} else {
    echo 'Error uploading file.';
}