HTML表单文件上载不上传文件

时间:2021-09-20 07:00:08

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.

但在我的前端代码中,它不会上传任何文件。我删除了所有的CSS和脚本以找出问题。

here is my simple front end HTML form :

这是我简单的前端HTML表单:

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

2 个解决方案

#1


6  

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

你忘了提到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


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.

问题在于

标记中的属性。要成功启用要在HTML中正确上载的文件,应遵循以下要求。

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

    确保表单使用method =“post”

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

    表单还需要以下属性: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.

因此,只需在

标记内添加此enctype =“multipart / form-data”部分即可。

#1


6  

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

你忘了提到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


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.

问题在于

标记中的属性。要成功启用要在HTML中正确上载的文件,应遵循以下要求。

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

    确保表单使用method =“post”

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

    表单还需要以下属性: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.

因此,只需在

标记内添加此enctype =“multipart / form-data”部分即可。