Files doesn't get uploaded though all back-end code is correct. I tested the back end code with another front-end styled code and it worked fine.
but in my front end code it doesn't upload any files. I removed all css and scripts as well to figure out the issue.
here is my simple front end HTML form :
<form action="upload_handler.php" method="post">
Select image to upload:
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="submit" value="Upload" name="submit">
</form>
HTML allows you to add the file upload functionality to your website by adding a file upload button to your webpage with the help of the <input> tag. The <input type=”file”> defines a file-select field and a “Browse“ button for file uploads.
Turn off Data Loss Prevention (or the file upload option will be greyed out) If your administrator has turned on data loss prevention this can also lead to the file upload option being greyed out as well.
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>
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With