get the file extension during php download


I try to add the file extension to my file during the download. As I find it hard to do, I already coded it in a small .jpeg case in my script. How can I get rid of the hard coded file extension and dynamically replace it with the original loaded as it could be gif, pdf etc.

The answer

$_FILES['file']['tmp_name'] that you use contains a temporary file name for the downloaded file. But if you want the original filename, including the extension, use $_FILES['file']['name'] .