PDF Generation from other server and Saving the pdf our server



For Creating PDF another server
<?
define('ROOT_DIR_PATH',"/home/demoweballiance/public_html/folder-name-pdfs/");

//$url = $frontEndURL."/admin/purchase_order/index?page=view_purchase_order_pdf&po_id=$id&hide_top=1&hide_left=1&print_pdf=1";

$url = $_REQUEST['url'];


if(isset($_REQUEST['print_url'])){
	
	echo "<a target='_blank' href='$url'>$url</a>";
	die;
}
$pdf_name = $_REQUEST['pdf_name'];
//unlink("".ROOT_DIR_PATH."'temp-pdfs/".$pdf_name);
$file_path = ROOT_DIR_PATH."/temp-pdfs/".$pdf_name;
exec("wkhtmltopdf '$url' '$file_path'");
sleep(1);

if(file_exists(ROOT_DIR_PATH."/temp-pdfs/$pdf_name")){	
	ob_clean();
	header("Location: $frontEndURL"."temp-pdfs/$pdf_name");
	exit;
}
?>


For fetching Pdf from another server which was created using above code and saving on our server
<?
define("ROOT_PATH",'/home2/weballia/public_html/folder_path/');
define("FOLDER_PATH",'generated_pdfs/'); 
define("PDF_FOLDER_PATH",ROOT_PATH.FOLDER_PATH);

$url = $_REQUEST['url'];
$pdf_name = $_REQUEST['pdf_name'];

$attachment_url = "https://demo.web-alliance.uk/folder_path/create-pdf.php?pdf_name=$pdf_name&url=$url";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $attachment_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);



$data = curl_exec($ch);
curl_close($ch);
file_put_contents(PDF_FOLDER_PATH."".$pdf_name,$data);


ob_clean();
header("Location: https://abc.co.uk/".FOLDER_PATH."$pdf_name");
exit;

//https://abc.co.uk/generate-pdf-with-url.php?pdf_name=testing123.pdf&url=https://abc.co.uk/admin/index.php?l=2
?>