简体   繁体   中英

Give the name to the output PDF file from MYSQL database

I have been generating the PDFs and download it. Everything works fine. But whenever the file is output, it simply replaces the previous generated file.

Is there any way to output the file with the different name every time the NEW user downloads it by selecting data from the database?? What changes I can make in Output() method?

I have read output() doc .

        $mpdf->Output("PDFs/something.pdf");

// change the path to fit your websites document structure

        $fullPath = "PDFs/something.pdf";

You can do:

$filename = 'pdf' . time(). '.pdf';
$mpdf->Output("PDFs/$filename");

You can attach some timestamp/date with filename.

$filename = "PDFs/something-" . time() . ".pdf"; $mpdf->Output($filename);

// change the path to fit your websites document structure

    $fullPath = $filename;

With the help of the answer given by Ramesh and some help from Immibis, I have found my way like this. Since the 'proposal_id' will always be unique in my case, so there will be no chance of downloading two pdfs of same id at the same time by different users.

$con = mysqli_connect("localhost","root","","my_db");
$name="Select name FROM table_name WHERE proposal_id= '$id'";
$name_result= mysqli_query($con,$name);
$row_name= mysqli_fetch_array($name_result); 

$filename = $row_name['name']. time();
$mpdf->Output("PDFs/$filename.pdf");

$fullPath = "PDFs/$filename.pdf";

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