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

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

am 25.01.2010 11:03:46 von SED

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.

Regards,
Summi




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

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

am 25.01.2010 11:10:34 von Lester Caine

SED wrote:
> 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.

http://uk.php.net/manual/en/function.tempnam.php any use ...

--
Lester Caine - G8HFL
-----------------------------
Contact - http://lsces.co.uk/wiki/?page=contact
L.S.Caine Electronic Services - http://lsces.co.uk
EnquirySolve - http://enquirysolve.com/
Model Engineers Digital Workshop - http://medw.co.uk//
Firebird - http://www.firebirdsql.org/index.php

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

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

am 25.01.2010 11:22:07 von Richard

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:

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

--
Richard Heyes
HTML5 canvas graphing: RGraph - http://www.rgraph.net (updated 23rd January)

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

Re: How to change a filename for download (e.g. jpeg, pdfetc.)

am 25.01.2010 11:32:38 von Ashley Sheridan

--=-d4f5DuT1yC+XLVqz/OuI
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

On Mon, 2010-01-25 at 10:03 +0000, SED wrote:

> 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.
>
> Regards,
> Summi
>
>
>
>


I save the file using the temp filename given to it by PHP during the
upload process. If that's not possible, then some sort of hash (MD5 for
example) of the original file name would suffice. Then, when the user
requests that file, they have to request it with a URL like
file.php?file=hashname

The added benefit of this is that you can verify the user is logged in
or not too. The only problem would be if you were serving media files,
as no plugins I know of send all the correct headers for the media file
request, so your browser would see it as an anonymous request.

Thanks,
Ash
http://www.ashleysheridan.co.uk



--=-d4f5DuT1yC+XLVqz/OuI--

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

am 25.01.2010 11:52:48 von Bouffa

--0016e6d6246980db2b047dfaf97c
Content-Type: text/plain; charset=ISO-8859-1

take a look at this :

http://www.phpclasses.org/browse/package/3220.html


On Mon, Jan 25, 2010 at 11:32 AM, Ashley Sheridan
wrote:

> On Mon, 2010-01-25 at 10:03 +0000, SED wrote:
>
> > 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.
> >
> > Regards,
> > Summi
> >
> >
> >
> >
>
>
> I save the file using the temp filename given to it by PHP during the
> upload process. If that's not possible, then some sort of hash (MD5 for
> example) of the original file name would suffice. Then, when the user
> requests that file, they have to request it with a URL like
> file.php?file=hashname
>
> The added benefit of this is that you can verify the user is logged in
> or not too. The only problem would be if you were serving media files,
> as no plugins I know of send all the correct headers for the media file
> request, so your browser would see it as an anonymous request.
>
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>
>
>

--0016e6d6246980db2b047dfaf97c--

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

am 05.02.2010 14:30:35 von SED

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=3D"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@gmail.com [mailto:richard.heyes@gmail.com] On Behalf =
Of
Richard
Sent: 25. jan=FAar 2010 10:16
To: SED
Cc: php-general@lists.php.net
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:

header('Content-disposition: attachment; filename=3Dfname.ext');
?>

--=20
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