What potential issues can arise when passing a file input from HTML to PHP using POST method?

One potential issue that can arise when passing a file input from HTML to PHP using the POST method is that the file may not be properly uploaded to the server due to incorrect handling or configuration. To solve this issue, make sure that the form tag in your HTML includes the attribute enctype="multipart/form-data" to properly handle file uploads. Additionally, in your PHP script, use the $_FILES superglobal array to access the uploaded file and move it to the desired location on the server.

<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $file = $_FILES["fileInput"];
    
    if ($file["error"] == UPLOAD_ERR_OK) {
        $uploadDir = "uploads/";
        $uploadFile = $uploadDir . basename($file["name"]);
        
        if (move_uploaded_file($file["tmp_name"], $uploadFile)) {
            echo "File uploaded successfully.";
        } else {
            echo "Error uploading file.";
        }
    } else {
        echo "Error: " . $file["error"];
    }
}
?>