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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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: richard.heyes@xxxxxxxxx [mailto:richard.heyes@xxxxxxxxx] On Behalf Of
Richard
Sent: 25. janúar 2010 10:16
To: SED
Cc: php-general@xxxxxxxxxxxxx
Subject: Re:  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




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux