Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Laravel PHP Excel导出内存已检查_Php_Laravel_Laravel 5_Phpexcel - Fatal编程技术网

Laravel PHP Excel导出内存已检查

Laravel PHP Excel导出内存已检查,php,laravel,laravel-5,phpexcel,Php,Laravel,Laravel 5,Phpexcel,因此,我在将数据导出到excel时出错 Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 72 bytes) in /home1/greatsup/public_html/system/application/vendor/phpoffice/phpexcel/Classes/PHPExcel/Cell.php on line 889 这是令人惊讶的,因为我导出的表只包含10行。因此

因此,我在将数据导出到excel时出错

Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 72 bytes) in /home1/greatsup/public_html/system/application/vendor/phpoffice/phpexcel/Classes/PHPExcel/Cell.php on line 889
这是令人惊讶的,因为我导出的表只包含10行。因此,我首先尝试打印它,以查看是否有任何数据正在提取,但仍然得到相同的错误

PS:我尝试在更大的数据集上使用excel导出。但是在这个控制器中,我很难找出问题所在

这是我的密码

 public function excel_export(Request $request) {

    $post = $request->all();
    $dateFrom = $post['updated_at_from'];
    $dateTo = $post['updated_at_to'];

    error_reporting(E_ALL);
    ini_set('display_errors', TRUE);
    ini_set('display_startup_errors', TRUE);
    date_default_timezone_set('Asia/Manila');
    if (PHP_SAPI == 'cli')
        die('This example should only be run from a Web Browser');
    $objPHPExcel = new PHPExcel();
    $objPHPExcel = PHPExcel_IOFactory::load("templates/unit_specifications_format.xlsx");
    $objPHPExcel->getProperties()->setCreator(Config::$APPNAME)
                                 ->setLastModifiedBy(Config::$APPNAME)
                                 ->setTitle(null)
                                 ->setSubject(null)
                                 ->setDescription(null)
                                 ->setKeywords(null)
                                 ->setCategory(null);
    $fontSettings = array(
    'font'  => array(
        'bold'  => true,
        'color' => array('rgb' => 'FFFFFF'),
        'size'  => 12,
        'name'  => 'calibri'
    ));
    $headerSettings = array('fill' => array(
    'type'  => PHPExcel_Style_Fill::FILL_SOLID,
    'color' => array('rgb' => \App\Resources\Config::$PRIMARYCOLOR)
    ));
    $borderSettings = $BStyle = array(
      'borders' => array(
        'allborders' => array(
          'style' => PHPExcel_Style_Border::BORDER_THIN
        )
      )
    );

    $query = DB::table('unit_specifications')->get();
    print_r($query);
    exit;


    $objPHPExcel->setActiveSheetIndex(0);
    $sheet = $objPHPExcel->getActiveSheet();

    $start = 5;
    $row = $start;
    $column = 0;
    $no = 1;




    $allCombination = PHPExcel_Cell::stringFromColumnIndex(0).$start.':'.PHPExcel_Cell::stringFromColumnIndex($column-1).($row-1);
    $sheet->getStyle($allCombination)->applyFromArray($borderSettings);
    header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
    header('Content-Disposition: attachment;filename="'.$this->excel_filename.'"');
    header('Cache-Control: max-age=0');
    header('Cache-Control: max-age=1');
    header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
    header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
    header ('Cache-Control: cache, must-revalidate');
    header ('Pragma: public');
    $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
    $objWriter->save('php://output');
    exit;
}

有什么想法我错过了吗?

如果您不确定PHP内存限制设置为什么,那么错误消息中将包含它。不过,大小是以字节为单位报告的,因此我们为您进行了一些转换:

PHP: Fatal Error: Allowed Memory Size of 8388608 Bytes Exhausted - 8 MB
PHP: Fatal Error: Allowed Memory Size of 16777216 Bytes Exhausted - 16 MB
PHP: Fatal Error: Allowed Memory Size of 33554432 Bytes Exhausted - 32 MB
PHP: Fatal Error: Allowed Memory Size of 67108864 Bytes Exhausted - 64 MB
PHP: Fatal Error: Allowed Memory Size of 134217728 Bytes Exhausted - 128 MB
PHP: Fatal Error: Allowed Memory Size of 268435456 Bytes Exhausted - 256 MB
PHP: Fatal Error: Allowed Memory Size of 536870912 Bytes Exhausted - 512 MB
PHP: Fatal Error: Allowed Memory Size of 1073741824 Bytes Exhausted - 1 GB
要解决此错误,请转到php.ini

ini_set('memory_limit', '1024M'); // or you could use 1G
这取决于您使用的Apache,其中大多数使用word

内存限制

所以搜索这个词,修改它,检查你的数据
希望这能解决您的问题

您可能希望使用。