RE: [PHP] How to change a filename for download (e.g. jpeg, pdf etc.)

[email protected] ("SED")
Newsgroups php.general
Message-ID <01d901caa667$666c0d00$33442700$@is>
Hi,

I finally got the time to test your solutions, the following is the best
solution and causes a minimum stress on the server and a decent security.

	header('Content-type: application/pdf');
	header('Content-Disposition: attachment;
filename="downloaded.pdf"');
	readfile('original.pdf');
	header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
	header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the
past

(Script from php.net based on your hints.)

I have tested this in many ways, but before I did not know how this was
simple.

SED


-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of
Richard
Sent: 25. janúar 2010 10:16
To: SED
Cc: [email protected]
Subject: Re: [PHP] How to change a filename for download (e.g. jpeg, pdf
etc.)

Hi,

> Can anyone point me to tutorials on how to change a filename for each
> download? My goal is to give the downloader a random name for a picture or
a
> document, so he will never know what the original filename is.

Try adding a Content-Disposition header:

<?php
    header('Content-disposition: attachment; filename=fname.ext');
?>

-- 
Richard Heyes
HTML5 canvas graphing: RGraph - http://www.rgraph.net (updated 16th January)
Follow me on Twitter: http://twitter.com/_rgraph
Lots of PHP and Javascript code - http://www.phpguru.org
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.