I need to make my website automatically download the pdf that I generated it, so I used this code to generate the pdf using dompdf :
include('pdf.php');
$file_name = "ORDER-".$name . '.pdf';
$html_code = '<link rel="stylesheet" href="bootstrap.min.css">';
$html_code .= fetch_customer_data();
$pdf = new Pdf();
$pdf->load_html($html_code);
$pdf->render();
$file = $pdf->output();
file_put_contents($file_name, $file);
when I run this in localhost the pdf downloaded in the same file where the source code file exists and everything is fine , but when I tried to run it on a real server I could not find the pdf so I used this code so it would be automatically downloaded in the downloads file :
header('Content-Type: application/download');
header("Content-Disposition: attachment; filename=\"" . $file_name . "\"");
header("Content-Length: " . filesize($file_name));
so this done the job but when I open the file I find it empty or with the result of the code source page I don't know what is wrong here can anyone tell me
the pdf.php file :
<?php
//pdf.php
require_once 'dompdf/autoload.inc.php';
use Dompdf\Dompdf;
class Pdf extends Dompdf{
public function __construct(){
parent::__construct();
}
}
?>