merge($name, $rpts); } function merge($name, $rpts, $debug = "") { $output_file_name = $name; $target = tempnam("/tmp", uniqid("target", true)); $merge_cmd = "/usr/bin/pdfunite"; $base_url = "http://localhost/"; $fnames_del = []; foreach ($rpts as $r) { $fname = tempnam("/tmp", uniqid("src", true)); $url = $r; $rpt_data = file_get_contents($url); if (strlen($rpt_data) > 0) { file_put_contents($fname, $rpt_data); $merge_cmd .= " $fname "; } $fnames_del[] = $fname; } $merge_cmd .= " $target"; if ($debug != "") { echo $merge_cmd; exit; } $output = []; exec($merge_cmd, $output); header("Content-type: application/pdf"); header( 'Content-Disposition: inline; filename="' . $output_file_name . '"' ); echo file_get_contents($target); foreach ($fnames_del as $fdel) { unlink($fdel); } if (file_exists($target)) { unlink($target); } exit; } }