Html 如何使用html将文件上传到我的服务器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5628011/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to upload a file to my server using html
提问by dave
basically i have this form that allows user to upload to my server:
基本上我有这个表格,允许用户上传到我的服务器:
<form id = "uploadbanner" method = "post" action = "#">
<input id = "fileupload" type = "file" />
<input type = "submit" value = "submit" id = "submit" />
</form>
But the problem is that when i upload a file, then click submit, i don't see the file upload in the server directory.
但是问题是,当我上传文件,然后单击提交时,我在服务器目录中看不到文件上传。
回答by Calum
<form id="uploadbanner" enctype="multipart/form-data" method="post" action="#">
<input id="fileupload" name="myfile" type="file" />
<input type="submit" value="submit" id="submit" />
</form>
To upload a file, it is essential to set enctype="multipart/form-data"
on your form
要上传文件,必须enctype="multipart/form-data"
在表单上进行设置
You need that form type and then some php to process the file :)
您需要该表单类型,然后是一些 php 来处理文件:)
You should probably check out Uploadifyif you want something very customisable out of the box.
如果您想要开箱即用的非常可定制的东西,您可能应该查看Uploadify。
回答by Darren
You need enctype="multipart/form-data"
otherwise you will load only the file name and not the data.
您需要enctype="multipart/form-data"
否则您将只加载文件名而不加载数据。
回答by Dane
On top of what the others have already stated, some sort of server-side scripting is necessary in order for the server to read and save the file.
除了其他人已经说过的内容之外,还需要某种服务器端脚本,以便服务器读取和保存文件。
Using PHP might be a good choice, but you're free to use any server-side scripting language. http://www.w3schools.com/php/php_file_upload.aspmay be of use on that end.
使用 PHP 可能是一个不错的选择,但您可以随意使用任何服务器端脚本语言。http://www.w3schools.com/php/php_file_upload.asp可能在这方面有用。