手机端多文件上传

<form    id='uploadForm'  enctype='multipart/form-data'>
    <link href="/Public/css/bootstrap.min.css" rel="stylesheet">//这句可以不要
    <link href="/Public/css/bootstrap-fileinput.css" rel="stylesheet">
    <tr>
    <input type="hidden" name="wxpic" id='wxpic' value="{$user_data['wxpic']}">
        <th>微信二维码</th>
        <td>
             <div class="form-group">
                <div class="fileinput fileinput-new" data-provides="fileinput" id="exampleInputUpload">
                    <div class="fileinput-new thumbnail" style="width: 200px;height: auto;max-height:150px;">
                        <img id="picImg" style="width: 100%;height: auto;max-height: 140px;" src="{$user_data['wxpic']}" alt="">
                    </div>
                    <div class="fileinput-preview fileinput-exists thumbnail" style="max-width: 200px; max-height: 150px;"></div>
                    <div>
                        <span class="btn btn-primary btn-file">
                            <span class="fileinput-new">选择文件</span>
                            <span class="fileinput-exists">换一张</span>
                            <input type="file" name="wxpic1" id="picID" accept="image/gif,image/jpeg,image/x-png">
                        </span>
                        <a href="javascript:;" class="btn btn-warning fileinput-exists" data-dismiss="fileinput">移除</a>
                        <a href="javascript:;" class="btn btn-warning fileinput-exists" id="uploadSubmit">上传</a>
                    </div>
                </div>
            </div>
        </td>
    </tr>
</form>
<script src="/Public/js/jquery-1.11.0.min.js" type="text/javascript"></script>
<script src="/Public/js/bootstrap-fileinput.js" type="text/javascript"></script>
<script type="text/javascript">
    $(function () {
        //比较简洁,细节可自行完善
        $('#uploadSubmit').click(function () {
            var data = new FormData($('#uploadForm')[0]);

            console.log(data);
            $.ajax({
                url: '/uploadimg',
                type: 'POST',
                data: data,
                async: false,
                cache: false,
                contentType: false,
                processData: false,
                success: function (data) {
                    if(data.status == 1){
                        $("#wxpic").val(data.imgurl);
                    }else{
                        console.log(data.message);
                    }
                },
                error: function (data) {
                    console.log(data.status);
                }
            });
        });

    })
</script>

Bootstrap Fileinput Demo_files.rar

tp3.2.3

public function uploadimg(){
        $upload = new \Think\Upload();// 实例化上传类
        $upload->maxSize   =     3145728 ;// 设置附件上传大小
        $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
        $upload->rootPath  =     './Uploads/'; // 设置附件上传根目录
        $upload->savePath  =     ''; // 设置附件上传(子)目录
        // 上传文件 
        $info   =   $upload->upload();
        if(!$info) {// 上传错误提示错误信息
            $this->error($upload->getError());
        }else{// 上传成功
            $url = '/Uploads/'.$info['wxpic1']['savepath'].$info['wxpic1']['savename'];
            $this->success('上传成功!','',['imgurl'=>$url]);
        }
    }


打赏

看恩吧
网站不承担任何有关评论的责任
  • 最新评论
  • 总共条评论
取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦