TP5.1+阿里雲OSS上傳+layui上傳文件


插件合集

點擊跳轉

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() . "\n");
        }  // 獲取圖片信息。

        $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');
        }
    }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM