简体   繁体   中英

PHPExcel Allowed memory size of exhausted

I'm creating big excel file with images, and now i have this problem. Without images all works good. In addition to this, i can't increase memory limit.

What should i do? I can't find real code examples, i've heard about reader but i don't understand how to use it right.

foreach ($array as $key => $value) {
    $sheet->setCellValue("A".$i, $value['articul']);
    $sheet->setCellValue("B".$i, $value['text']);

    //uploading image to my server

    $type_img = explode( ".",$value['image']);
    $type_img =  ".".end($type_img);
    $pht_lnk = $value['image'];
    $photoname = explode("/", $value['image']);
    $photoname = end($photoname);
    $dir_upl = 'img/'.$photoname;
    if (!fileExists($dir_upl)) {
        if(file_put_contents($dir_upl, file_get_contents($pht_lnk))) { 
            $imagePath = $dir_upl;
        }
        else{
            $imagePath = NULL;
        }
    }
    else{
        $imagePath = $dir_upl;
    }

    //here i'm trying to add image

    if (file_exists($imagePath)) {
        $imgg = new PHPExcel_Worksheet_Drawing();
        $imgg->setPath($imagePath);
        $imgg->setCoordinates("C".$i);             
        $imgg->setOffsetX(0);
        $imgg->setOffsetY(0);    
        $sheet->getRowDimension(2)->setRowHeight(190);
        $imgg->setWorksheet($sheet);
    } 
    $sheet->setCellValue("D".$i, $value['price']);
    $i++;
}

If you cant increase memory limit try another libs

PHP-Export-Data by Eli Dickinson

simple excel

PHP_XLSXWriter

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM