doudou8783 2019-02-02 10:48
浏览 86

在imagick中生成fopen文件的问题

In Imagick I am trying to do the following: When accessing .php already begins the download of .jpg, I do not even need a preview just the multiple download because this .pdf in question will always have two pages, with that fopen I can download only the first page, for some reason it does not download the second page.

pdf_file = './programming/'.$date.'.pdf';
$mpdf->Output($pdf_file);

$img = new imagick();
$img->setResolution(200,200);
$img->readImage($pdf_file);
$img->setImageUnits(imagick::RESOLUTION_PIXELSPERINCH);
$img->setImageFormat('jpg');
$img->setImageCompressionQuality(85);

$pages = $img->getNumberImages();
if ( $pages ) {
        foreach($img as $i => $img_file){
            $img_file->writeImage('./programming/('.$i.') '.$date.'.jpg');
            $img_path = './programming/('.$i.') '.$date.'.jpg';
            header('Content-Type: application/download');
            header('Content-Disposition: attachment; filename="('.$i.') '.$date.'.jpg"');
            header("Content-Length: " . filesize($img_path));

            $fp = fopen($img_path, "rb");
            fpassthru($fp);
            fclose($fp);
        }
} else {
        echo '<h2>Not Found.</h2>';
}

$img->clear();
$img->destroy();

If anyone can guide me, I may have missed something!

Thank you in advance for your attention!

Note: The images that represent page 1 and 2 of the .pdf are already saved in ./programming/ folder, the code works well in that case, then the foreach did what I expected, created two images and stored them but only download one with fopen

  • 写回答

0条回答 默认 最新

    报告相同问题?