Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open Download Dialog with PHP

Tags:

php

download

I am trying to make an online kickstart config file creator. After the file is created on the server how do I get the download dialog to pop up so the user can download it?

like image 212
cskwrd Avatar asked Jun 12 '09 05:06

cskwrd


People also ask

How can you display a file download dialog box using PHP?

By using the HTTP header Content-Disposition: attachement, you can also supply or add a recommended filename to be displayed by the download dialog box. This is done using a concatenated filename attribute. When no filename is specified, the current script filename is used.

How to download pdf using PHP?

To Download PDF from HTML link using PHP with the help of header() function in php. The header()function is used to send a raw HTTP header. Sometimes it wants the user to be prompted to save the data such as generated PDF. header("Content-Length: " .

How to download html file in PHP?

$file; // Process download if (file_exists($filepath)) { header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename="' . basename($filepath) .


2 Answers

Content-Disposition header..

// We'll be outputting a PDF
header('Content-type: application/pdf');
// It will be called downloaded.pdf
header('Content-Disposition: attachment; filename="downloaded.pdf"');
// The PDF source is in original.pdf
readfile('original.pdf');

http://au2.php.net/manual/en/function.header.php

like image 169
russau Avatar answered Nov 10 '22 09:11

russau


the magic is in the content-disposition

send a file to client

like image 23
Al W Avatar answered Nov 10 '22 09:11

Al W