前端做input表单,type=file怎样提交给后台
展开全部
1、首先,你要对form表单设置下相关属性,增加如下属性:
enctype="multipart/form-data" action="接收上传文件的后台处理URL" method="post"
<form enctype="multipart/form-data" action="" method="post">
<input type="file" <a href="https://www.baidu.com/s?wd=id&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1Y4njfzmvDzPWu9uHKWPWR40ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EnH6krjD1PHbdPHDdrHDkn1bYr0" target="_blank" class="baidu-highlight">id</a>="choosefile" />
<input type="file" <a href="https://www.baidu.com/s?wd=id&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1Y4njfzmvDzPWu9uHKWPWR40ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EnH6krjD1PHbdPHDdrHDkn1bYr0" target="_blank" class="baidu-highlight">id</a>="f" style="display:none;" />
<input type="submit" value="上传文件" <a href="https://www.baidu.com/s?wd=id&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1Y4njfzmvDzPWu9uHKWPWR40ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EnH6krjD1PHbdPHDdrHDkn1bYr0" target="_blank" class="baidu-highlight">id</a>="submitBtn" />
</form>
2、编写接收客户端文件上传的后台代码,即上面提到的“接收上传文件的后台处理URL”的相关代码。
3、当点击上面增加的“上传文件”按钮后,将调用action对应的处理方法进行文件上传
因为不知道你是使用什么语句作为后台程序的运行语句,这里没法给出示例。像很多都有现成的插件。
enctype="multipart/form-data" action="接收上传文件的后台处理URL" method="post"
<form enctype="multipart/form-data" action="" method="post">
<input type="file" <a href="https://www.baidu.com/s?wd=id&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1Y4njfzmvDzPWu9uHKWPWR40ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EnH6krjD1PHbdPHDdrHDkn1bYr0" target="_blank" class="baidu-highlight">id</a>="choosefile" />
<input type="file" <a href="https://www.baidu.com/s?wd=id&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1Y4njfzmvDzPWu9uHKWPWR40ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EnH6krjD1PHbdPHDdrHDkn1bYr0" target="_blank" class="baidu-highlight">id</a>="f" style="display:none;" />
<input type="submit" value="上传文件" <a href="https://www.baidu.com/s?wd=id&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1Y4njfzmvDzPWu9uHKWPWR40ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EnH6krjD1PHbdPHDdrHDkn1bYr0" target="_blank" class="baidu-highlight">id</a>="submitBtn" />
</form>
2、编写接收客户端文件上传的后台代码,即上面提到的“接收上传文件的后台处理URL”的相关代码。
3、当点击上面增加的“上传文件”按钮后,将调用action对应的处理方法进行文件上传
因为不知道你是使用什么语句作为后台程序的运行语句,这里没法给出示例。像很多都有现成的插件。
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询