博客列表 >Fastadmin在弹窗层上传文件

Fastadmin在弹窗层上传文件

鱼的熊掌
鱼的熊掌原创
2022年09月05日 15:40:331227浏览

在add.hml导入excel
html代码

  1. //在弹窗的页面js引用上传组件
  2. template: function () {
  3. Table.api.init({
  4. extend: {
  5. import_url: 'yq/flowld/import'
  6. }
  7. });
  8. require(['upload'], function (Upload) {
  9. Upload.api.plupload($(".btn-import"), function (data, ret) {
  10. Fast.api.ajax({
  11. url: "yq/flowld/import", //上传接收地址
  12. data: {file: data.url},
  13. success: function (response) {
  14. console.log(response);
  15. layer.closeAll();
  16. }
  17. }, function (data, ret) {
  18. // console.log(data);
  19. // console.log(ret);
  20. });
  21. });
  22. });
  23. Controller.api.bindevent();
  24. }

JS代码

  1. /**
  2. * @description: 导入
  3. * @return {*}
  4. */
  5. public function import()
  6. {
  7. $file = $this->request->request('file');
  8. if (!$file) {
  9. $this->error(__('Parameter %s can not be empty', 'file'));
  10. }
  11. $filePath = ROOT_PATH . DS . 'public' . DS . $file;
  12. if (!is_file($filePath)) {
  13. $this->error(__('No results were found'));
  14. }
  15. $objReader = \PHPExcel_IOFactory::createReader('Excel2007');
  16. $objPHPExcel = $objReader->load($filePath, $encode = 'utf-8');
  17. $sheet = $objPHPExcel->getSheet(0);
  18. $highestRow = $sheet->getHighestRow(); // 取得总行数
  19. $highestColumn = $sheet->getHighestColumn(); // 取得总列数
  20. $this->success('111');
  21. }

PHP

声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议