doujingjiao0015 2018-09-17 07:08 采纳率: 0%
浏览 169

Laravel FatalErrorException:内存不足

I am trying to export my zip file but I get the error:

Fatal Error Exception in ProjectFinding.php line 387:
Out of memory (allocated 382468096) (tried to allocate 1346263 bytes)

php.ini set memory_limit=2048M. Is there something wrong? Please tell me why this error due error in code or memory and how to fix this error?

It shows error in this line

 $zip->addFromString($nfile[1], file_get_contents($file));
  • 写回答

1条回答 默认 最新

  • doulang6695 2018-09-17 07:27
    关注
    public function excel_exports($input, $p_id) {
            $find = new Project();
            $tmp_name = time();
            $path = storage_path("files/" . $p_id);
            if (!is_dir($path)) {
                umask(0);
                mkdir($path, 0777, true);
                chmod($path, 0777);
            }
    
            $project = new Project();
            $prodata = $project->getById($p_id);
            $zipfile = $prodata->id.'.zip';
            $excelname = $prodata->id;
            $data = $findingObj->getAll($p_id);
            $colspan = 1;
            foreach ($data as $row) {
                $this->_saveDocumentsFiles($row);
                $doc_cc = 0;
                foreach ($row->document as $doc) {
                    $doc_cc = $doc_cc + $doc->doc_files->count();
                }
                if ($doc_cc > $colspan) {
                    $colspan = $doc_cc;
                }
            }
            Excel::create($excelname, function($excel) use ($data, $colspan) {
                $excel->sheet('projectfinding', function($sheet) use ($data, $colspan) {
                    $sheet->loadView('admin.project.finding.excel_file_exports')->with(["targetRow" => 5, "targetCol" => "A", "targetView" => "admin.project.finding.excel_pdf", 'data' => $data, 'colspan' => $colspan]);
                });
            })->save('xls', $path, false);
            $source = storage_path('files');
            $this->zip($source, $zipfile);
            header("Content-type: application/zip");
            header("Content-Disposition: attachment; filename=$zipfile");
            readfile($zipfile);
            unlink(public_path($zipfile));
            $rmpath = storage_path("files/" . $p_id);
            $this->_rrmdir($rmpath);
            return true;
        }
    
    in this code i simply change p_id with id it will show error in $path and $rmpath
    
    评论

报告相同问题?

悬赏问题

  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致