PHP 多input file文件上传
- 前台html
- jquery代码
- 后台PHP处理
前台html
<form id="form" method="post" enctype="multipart/form-data">
<input class="imagesUpload" type="file" name="imagesUpload[]" style="width: 152px;"/>
<input class="imagesUpload" type="file" name="imagesUpload[]" style="width: 152px;"/>
<input class="imagesUpload" type="file" name="imagesUpload[]" style="width: 152px;"/>
<input class="imagesUpload" type="file" name="imagesUpload[]" style="width: 152px;"/>
<a class="easyui-linkbutton" icon="icon-add" id="uploadImage_input">图片上传</a>
</form>
** 注意name的写法,都要使用name[]方式,而且用同一个name
** 注意带有file的表单,form一定要加:enctype=”multipart/form-data”
jquery 提交form表单
$("#form").form('submit',{
url:url,
success:function(data){
//处理返回数据
}
});
PHP 后台处理
//接收处理文件
$fileArray = $_FILES['imagesUpload'];//依据请求的name获取文件
$upload_dir = public_path() . "/upload/carPic/";
$userID = Session::get('userID');
$nowTime = date("YmdHis", time());
$i = 0;
$successName = array();
foreach ($fileArray['error'] as $key => $error){ //遍历处理文件
if ( $error == UPLOAD_ERR_OK ) {
$temp_name = $fileArray['tmp_name'][$key];
$file_name = $userID.'-'.$nowTime.$i.$fileArray['name'][$key];
move_uploaded_file($temp_name, $upload_dir.$file_name);
array_push($successName, $file_name);//把上传成功的文件名增加数组
}else{
return '{"flag":0,"flagmsg":"上传[文件'.$key.']失败!<br/>!"}';
}
$i++;
}
$flag = array('flag'=>1,'flagmsg'=>'文件上传成功!');
$names = array('names'=>$successName);
return json_encode(
array_merge($flag,$names)
);//返回上传结果,并返回上传成功后的全部文件的名称
PHP代码都非常easy,就不一一解释了。欢迎指导。
尊重原创。转载请注明出处:http://blog.csdn.net/a437629292/article/details/44337295
PHP 多input file文件上传的更多相关文章
- input file 文件上传标签的样式美化
input file 文件上传标签的样式美化 将<input type="file">的透明度设置为0: <input type="file" ...
- js 实现 input file 文件上传
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat=&qu ...
- input file 文件上传,js控制上传文件的大小和格式
文件上传一般是用jquery的uploadify,比较好用.后面会出文章介绍uploadify这个插件. 但是,有时候为了偷懒,直接就用input 的file进行文件和图片等的上传,input fil ...
- 修改input file 文件上传的样式
Web页面中,在需要上传文件时基本都会用到<input type="file">元素,它的默认样式: chrome下: IE下: 不管是上面哪种,样式都比较简单,和很多 ...
- input file文件上传样式
<style> .file-group { position: relative; width: 200px; height: 80px; ...
- js 实现 input type="file" 文件上传示例代码
在开发中,文件上传必不可少但是它长得又丑.浏览的字样不能换,一般会让其隐藏点其他的标签(图片等)来时实现选择文件上传功能 在开发中,文件上传必不可少,<input type="file ...
- [置顶] js 实现 <input type="file" /> 文件上传
在开发中,文件上传必不可少,<input type="file" /> 是常用的上传标签,但是它长得又丑.浏览的字样不能换,我们一般会用让,<input type ...
- 更改file文件上传默认CSS样式
前言: 多数时候我们需要表单上传文件,如图片.但是浏览器默认的input[file]样式很不友好, 需要我们自己手动修改. 如图基于bootstrap布局的表单, 但file文件上传样式不敢恭维. & ...
- FormData序列化及file文件上传
表单数据上传 情况一: 一.当表单文件处于无任何处理状态时,用submit提交直接上传; 但这种方式上传,数据无任何处理:(极少使用): 但是传统的表单提交会导致页面刷新,但是有些情况下,我们并不希望 ...
随机推荐
- Lake Counting (POJ No.2386)
有一个大小为N*M的园子,雨后积起了水,八连通的积水被认为是链接在一起的求出园子里一共有多少水洼? *** *W* *** /** *进行深度优先搜索,从第一个W开始,将八个方向可以到达的 W修改为 ...
- 文件MD5
package mainimport ( "crypto/md5" "fmt" // "github.com/astaxie/bee ...
- UGUI 滚动视图
滚动视图是常用的UI控件之一,它是由多个基本控件组合而成.如图 ==================================================================== ...
- Android应用程序窗口(Activity)的测量(Measure)、布局(Layout)和绘制(Draw)过程分析
文章转载至CSDN社区罗升阳的安卓之旅,原文地址:http://blog.csdn.net/luoshengyang/article/details/8372924 在前面一篇文章中,我们分析了And ...
- oninput,onpropertychange,onchange的使用方法和差别
1.前言 因为工作须要,需实现一个相似于微博输入框的功能,在用户动态输入文字的时候,改动提示“您还能够输入XX字”.例如以下图所看到的: 因此,略微研究了一下oninput,onpropertycha ...
- javax inect
Spring 3 and JSR-330 @Inject and @Named example By mkyong | September 16, 2012 | Viewed : 86,399 tim ...
- C# ?? 操作符示例
static int? GetNullableInt() { return null; } static string GetStringValue() { return null; } static ...
- java学习之i/o
基本的输入输出 这里有两种方法,其中一种被注释了,可以换着注释后测试一遍 class TestSystem { public static void main(String[] args) { /* ...
- Fedora下用Iptux,中文乱码解决
Ubuntu/Fedora下用Iptux与Windows下大飞鸽传书,中文乱码解决 问题描述: 在Ubuntu/Fedora下安装了Iptux后,再往Windows机器上发送文件或消息时,如果有中文, ...
- linux的find指令详解。
引用:http://os.51cto.com/art/200908/141411.htm http://www.oschina.net/translate/15-practical-linux-fin ...