zoukankan      html  css  js  c++  java
  • thinkphp结合layui上传视频

    JS示例:

    <script type="text/javascript">
    layui.use(['form', 'layedit','element', 'laydate','upload'], function(){
        var form = layui.form;
        var layer = layui.layer;
        var layedit = layui.layedit;
        var laydate = layui.laysdate;
        // 上传
        var upload = layui.upload;
        var uploadInst1 = upload.render({
        elem: '#uploadImgBut1', //绑定元素
        url: "{:U('Admin/Upload/uploadmedia')}",//上传接口
        accept: 'video',
        done: function(res){
            if(res['state'] ==1){
                layer.msg(res['message']);
                $("#uploadImg1").attr('src',res['path']).show();
                $("input#uploadImgSrc1").val(res['path']); 
            };
        }
        }); 
    });
    </script>

    PHP示例:

    public function uploadmedia(){      
        $upload = new ThinkUpload();// 实例化上传类
        $mediaSize = intval(CP('MEDIASIZE'));
        $mediaType = CP('MEDIATYPE');
        $mediaSize = !empty($mediaSize) ? $mediaSize : 3145728;
        $mediaType = !empty($mediaType) ? explode(',',$mediaType) : array('mp3','mp4');
        $upload->maxSize   =     $mediaSize;// 设置附件上传大小
        $upload->exts      =     $mediaType;// 设置附件上传类型 
        $upload->rootPath  =     "./Uploads/Video/"; // 设置附件上传根目录
        $upload->savePath  =     ''; // 设置附件上传(子)目录
        $dataArr = array();
        $dataArr['code'] = 1;
        $dataArr['msg'] = '上传成功';
        $dataArr['data']['src'] = "";
        $dataArr['data']['title'] = "错误";
        // 上传文件 
        $info = $upload->upload();
        if(!$info){
            $dataArr['code'] = 0;
            $dataArr['msg'] = '上传失败';
        };
        $path = "/Upload/Video/".$info['file']['savepath'].$info['file']['savename'];
        $dataArr['data']['src'] = $path;
        $dataArr['data']['title'] = "成功";
        exit(json_encode($dataArr));
    }
  • 相关阅读:
    HDU 2192 MagicBuilding
    HDU 2148 Score
    HDU 1847 Good Luck in CET4 Everybody!
    往CImageList中加图标列表
    LoadIcon
    OnInitialUpdate 详解
    设备坐标(DP)、客户坐标(Client)、逻辑坐标(LP)
    Web及网络基础学习(一)
    Qt 下QMessageBox下中文乱码问题
    vs2005菜单:选项项目和解决方案
  • 原文地址:https://www.cnblogs.com/e0yu/p/9353073.html
Copyright © 2011-2022 走看看