PHP(tp5.1)批量导入分页

js请求代码

 layui.use('upload', function() {
   
        var upload = layui.upload;
        var loading;
        //执行实例
        var uploadInst = upload.render({
   
            elem: '#export-excel1', //绑定元素
            url: '{:url("shop.shop/daoruShop")}', //上传接口
            before: function() {
   
                loading = layer.load(1);
            },
            choose: function() {
   
                layer.closeAll();
            },
            accept: 'file',
            done: function(res) {
   
                //上传完毕回调
                // layer.msg('上传成功',{icon:1,time:1500});
                if (res.code == '0') {
   
                    // $.msg.success('上传成功');
                    // $.tool.reload();
                    daoruShop(res.round,1,res.image)
                } else {
   
                    $.msg.error(res.msg);
                    $.tool.reload();
                }
            },
            error: function() {
   
                //请求异常回调
                layui.msg('上传失败', {
   
                    icon: 2,
                    time: 1500
                });
            }
        });
    });

    function daoruShop(round,page,image) {
   
        $.get('{:url("shop.Shop/daorufenpi")}', {
   
                round: round,
                page:page,
                image:image
            },
            function(data) {
   
                layer.msg(data.msg);
                if (data.code == 1) {
   
                    if (data.allpage + 1 > data.page) {
   
                        setTimeout(function() {
   
                            daoruShop(data.round,data.page,data.image);
                        }, 1400)
                    } else {
   
                        layer.closeAll();
                        location.reload();
                        // window.location.href = '{:url("shop.Shop/daorufenpi")}?round='+data.round + '&page=' + data.page + '&image=' + data.image;
                    }
                } else {
    
                    setTimeout(function() {
   
                        layer.msg(data.msg);
                        location.reload();
                        // layer.closeAll();
                    }, 1400)
                }
            }, "json");

    }

PHP代码

 public function daoruShop()
    {
   
        ini_set("memory_limit", "512M");
        $file = request()->file('file');
        if ($file) {
   
            $file_types = explode(".", $_FILES['file']['name']); // ["name"] => string(25) "excel文件名.xls"
            $file_type = $file_types[count($file_types) - 1]; //xls后缀
            /*判别是不是.xls文件,判别是不是excel文件*/
            if (strtolower($file_type) != "xls" && strtolower($file_type) != "xlsx" && strtolower($file_type) != "csv") {
   
                $this->error('不是Excel文件,重新上传');
                die;
            }
            $a = dirname($_SERVER['SCRIPT_FILENAME']) . "/";
            $b = dirname(realpath($a)) . "/";
            $path = $b . 'public/upload/excel';
            $images = $b . 'public/static/uploads/shopImage';
            $info = $file->move($path);
            $file_path = $path . '/' . $info->getSaveName(); //上传后的EXCEL路径
            // 引入核心文件
            require '../vendor/phpoffice/phpexcel/Classes/PHPExcel/Reader/Excel2007.php';
            require '../vendor/phpoffice/phpexcel/Classes/PHPExcel/Reader/Excel5.php';
            if ($file_type == 'xlsx') {
   
                $objReader = new \PHPExcel_Reader_Excel2007();
                $objExcel = $objReader->load($file_path);
            } else if 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值