HTML Form File Uploads doesn't upload file

Solution 1:

you forgot to mention the enctype="multipart/form-data"

<form action="upload_handler.php" enctype="multipart/form-data" method="post">
    Select image to upload:
    <input type="file" name="fileToUpload" id="fileToUpload">
    <input type="submit" value="Upload" name="submit">
</form>

Solution 2:

The issue is with the attributes in your <form> tag. To successfully enable files to be uploaded properly in HTML, following requirements should be there.

  • Make sure that the form uses method="post"

  • The form also needs the following attribute: enctype="multipart/form-data".

It specifies which content-type to use when submitting the form

So just add this enctype="multipart/form-data" part inside your <form> tag.