Rename PHP Downloaded File in File Downloader/Accelerator Applications

Posted by Joe on Stack Overflow See other posts from Stack Overflow or by Joe
Published on 2010-05-26T01:36:22Z Indexed on 2010/05/26 1:41 UTC
Read the original article Hit count: 257

Filed under:

I have the following "download" script in PHP which basically makes an address on my website download the file for the user, eg. mysite.com/download.php?fileid=10

The question I have is, how can I send the file name to the used for the download when a user downloads the .php address with a File Downloaders/Accelerators? eg. "Content-Disposition" in this case makes the file called download.php where as I want it to be renamed to $downloadFileName as usual.

// Set headers
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Description: File Transfer");
header("Content-Type: application/force-download");
header("Content-Disposition: attachment; filename=\"".$downloadFileName."\"");
header("Content-Transfer-Encoding: binary");

// Read the file from disk
readfile($downloadLocation);

© Stack Overflow or respective owner

Related posts about php