HTML Form File Uploads doesn't upload file

早过忘川 提交于 2019-12-17 21:05:56

问题


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>

回答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>



回答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.



来源:https://stackoverflow.com/questions/34984907/html-form-file-uploads-doesnt-upload-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!