search
Homephp教程php手册PHP 多input file文件上传

PHP 多input file文件上传

前台html jquery代码 后台PHP处理

前台html



** 注意name的写法,都要使用name[]方式,并且用同一个name
** 注意带有file的表单,form一定要加:enctype=”multipart/form-data”

jquery 提交form表单

<code class="hljs" javascript="">$(#form).form(&#39;submit&#39;,{
  url:url,
  success:function(data){
    //处理返回数据
  }
});</code>

PHP 后台处理

<code class="hljs" php="">//接收处理文件
$fileArray = $_FILES[&#39;imagesUpload&#39;];//根据请求的name获取文件
$upload_dir = public_path() . /upload/carPic/;
$userID = Session::get(&#39;userID&#39;);
$nowTime = date(YmdHis, time());
$i = 0;
$successName = array();
foreach ($fileArray[&#39;error&#39;] as $key => $error){  //遍历处理文件
  if ( $error == UPLOAD_ERR_OK ) {
    $temp_name = $fileArray[&#39;tmp_name&#39;][$key];
    $file_name = $userID.&#39;-&#39;.$nowTime.$i.$fileArray[&#39;name&#39;][$key];
    move_uploaded_file($temp_name, $upload_dir.$file_name);
    array_push($successName, $file_name);//把上传成功的文件名称加入数组
  }else{
    return &#39;{flag:0,flagmsg:上传[文件&#39;.$key.&#39;]失败!
!}&#39;;
  }
  $i++;
}
$flag = array(&#39;flag&#39;=>1,&#39;flagmsg&#39;=>&#39;文件上传成功!&#39;);
$names = array(&#39;names&#39;=>$successName);
return json_encode(
  array_merge($flag,$names)
);//返回上传结果,并返回上传成功后的所有文件的名称</code>

PHP代码都很简单,就不一一解释了。欢迎指导!
 

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.