What are some common pitfalls or errors that can occur when using enctype="multipart/form-data" in PHP file upload scripts?

One common pitfall when using enctype="multipart/form-data" in PHP file upload scripts is forgetting to check if the file was actually uploaded before processing it. This can lead to errors if the file was not successfully uploaded. To solve this, always check if the file was uploaded using the "is_uploaded_file" function before processing it.

if(isset($_FILES['file']) && is_uploaded_file($_FILES['file']['tmp_name'])){
    // Process the uploaded file
    $file = $_FILES['file'];
    move_uploaded_file($file['tmp_name'], 'uploads/' . $file['name']);
    echo 'File uploaded successfully!';
} else {
    echo 'Error uploading file.';
}