html
<span class="posrelative scbox"> <img class="middle mr5" src="__INDEX__/images/sc_03.png"/>上传视频(按ctrl多选) <input class="upvideo" type="file" data-tid="<{$vo.tid}>" accept="video/*" multiple="multiple"/> </span>
js
/*上传视频*/ $(".upvideo").change(function(e) { var tishi=layer.msg('正在上传,请勿操作',{icon:16,time:60000}); var imgBox=e.target.files; for(var i=0;i<imgBox.length;i++){ var form=new FormData(); form.append('file',imgBox[i]); form.append('tid',$(this).data('tid')); form.append('num',i); $.ajax({ url:"<{:url('pupload')}>", data:form, type:"post", contentType: false,// jQuery不要去设置Content-Type请求头 processData: false,// jQuery不要去处理发送的数据 success:function(data){ console.log(data); if(data==imgBox.length-1){ layer.close(tishi); layer.msg('上传成功'+ (parseInt(data)+1) +"个",{icon:1,time:2000},function(){ window.location.reload(); }); } } }) } });
php
public function pupload(){ // 上传文件 $file = request()->file('file'); $info = $file->move( './upload'); $getSaveName=str_replace("\","/",$info->getSaveName()); $file = $_SERVER['DOCUMENT_ROOT'].'/upload/'.$getSaveName; $video = $getSaveName; $ossClient = new OssClient($this->config['cfg_accessKeyId'], $this->config['cfg_accessKeySecret'], $this->config['cfg_endpoint ']); $bucket= $this->config['cfg_bucket'];//oss中的文件上传空间 $object = $getSaveName;//想要保存文件的名称 try{ $arr=$ossClient->uploadFile($bucket,$object,$file); $arr['video'] = $arr['info']['url']; //这里可以删除上传到本地的文件。unlink($file); } catch(OssException $e) { //上传失败,自己编码 printf($e->getMessage() . " "); } // 获取图片信息。 $task = Task::find(Request::param('tid')); $task->type = 3; $task->save(); $taskinfo = Taskinfo::where('tid',Request::param('tid')) ->where('role',"拍客") ->where('uid',session('uid','',SESSIONINDEX)) ->find(); $taskinfo->state = "待审核视频"; $taskinfo->save(); $arr['tid'] = Request::param('tid'); $arr['uid'] = session('uid','',SESSIONINDEX); $arr['state'] = '待审核'; $video = new Video(); $res=$video -> save($arr); if($res){ echo (int)Request::param('num'); } }