views:

155

answers:

2

Hi

maybe this is ridiculous but i wonder if it is possible to let your user to download a file with a different name.

for example; there is a file called "4324ffsd34.jpg" and i want ppl to download it by download.php, with a different name( like "filetodownload.jpg" ). without renaming original file.

is that possible in any way?

thanks

+7  A: 

Sure, use a Content-disposition header

header('Content-Disposition: attachment; filename="filetodownload.jpg"');
David Caunt
yes i can see now, thx :), but i guess i must also use "readfile('original.pdf');" to do it
Ahmet vardar
Absolutely, and good to set the Content-Length and Content-Type too. You can use filesize() for the length and write your own function based on the extension to do content-type or use http://uk2.php.net/fileinfo
David Caunt
+3  A: 

Sure you can, just try something like this:

$original_filename = '4324ffsd34.jpg';

// headers to send your file
header("Content-Type: application/jpeg");
header("Content-Length: " . filesize($original_filename));
header('Content-Disposition: attachment; filename="filetodownload.jpg"');

// upload the file to the user and quit
readfile($original_filename);
exit;

Hope it helps!

Frankie