I have a website that lists attachments. Clicking on these attachments result in one of two types of behaviours –
- The attachment opens in the same window.
- The attachment presents the user with a dialog to open or save the document.
Number 1 appears to only be happening with PDF’s, but is there a way that I can make all attachments present the Save/Open/Cancel popup to users?
For the PDF only ..
…
for all other file type perhaps you could use ..
echo mime_content_type('Yourfile.ext')oBeware that I haven’t tested it…
The Content-type header specifies what type of file is to be downloaded, specified by a mime type.
The Content-Disposition header specifies a new filename for the file which is to be downloaded.
The readfile line is not a header being sent, but a PHP call that gets all the data from a file and outputs it. The argument you pass to the readfile function is the location of the actual pdf file to be downloaded.
UPDATE
mime_content_type()function is deprecated. you’ll ned to replace with this …