What are some potential pitfalls to be aware of when using an upload script with a file size limitation in PHP?

When using an upload script with a file size limitation in PHP, one potential pitfall to be aware of is that the upload script may not properly handle files that exceed the size limit. This could result in errors or unexpected behavior. To solve this issue, you can add server-side validation to check the file size before attempting to upload it.

// Set maximum file size limit (in bytes)
$maxFileSize = 1048576; // 1 MB

// Check if file size exceeds the limit
if ($_FILES['file']['size'] > $maxFileSize) {
    echo "Error: File size exceeds the limit of 1 MB.";
    exit;
}

// Continue with file upload process
// Your upload script code here...