• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

php 使用html5实现多文件上传实例

php 搞代码 3年前 (2022-01-22) 12次浏览 已收录 0个评论

首先向大家介绍一下html5中file的multiple属性

定义和用法

multiple 属性规定输入字段可选择多个值。如果使用该属性,则字段可接受多个值。

实例:

<form action="demo_form.asp" method="get"> Select images: <input type="file" name="img" multiple="multiple" /> <input type="submit" /></form>

上面实例中的input file 可接受多个文件上传字段。

了解了html5中file的multiple属性,下面我们开始讲解使用html5实现多文件上传。

实例代码:

html:

<!DOCTYPE html><html><head><meta charset="UTF-8"></head><body><form action="my_parser.php" m<a style="color:transparent">来@源gao*daima.com搞@代#码网</a><strong>搞gaodaima代码</strong>ethod="post" enctype="multipart/form-data"> <p><input name="upload[]" type="file" multiple="multiple" /></p> <input type="submit" value="Upload all files"></form></body></html>

php代码:

for($i=0; $i<count($_FILES['upload']['name']); $i++) { //Get the temp file path $tmpFilePath = $_FILES['upload']['tmp_name'][$i];  //Make sure we have a filepath if ($tmpFilePath != ""){  //Setup our new file path  $newFilePath = "./uploadFiles/" . $_FILES['upload']['name'][$i];   //Upload the file into the temp dir  if(move_uploaded_file($tmpFilePath, $newFilePath)) {    //Handle other code here   } }}

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

更多php 使用html5实现多文件上传实例相关文章请关注搞代码


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:php 使用html5实现多文件上传实例

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址