Download file - prompt for file name
Posted: Sat Sep 12, 2009 9:33 am
I am writing code that ends with a file download. My code creates the file name so the user cannot rename the file until after it is downloaded and saved to their hard drive. I want a suggested name to appear in the save dialogue but I want the user to have the option to change the name if they want. I have looked and found many examples of the version I am using that give the user no control over the name. Here is my code:
Code: Select all
$filename = $data_store['exp_weblogs']['data'][0]['blog_title']
.date(" m-d-Y g.i.s a")
.'.wblg';
$browser_agent = "";
$mime_type = ($browser_agent == 'IE' || $browser_agent == 'OPERA') ? 'application/octetstream' : 'application/octet-stream';
header('Content-Type: ' . $mime_type);
if ($browser_agent == 'IE')
{
header('Content-Disposition: inline; filename="' . $filename . '"');
header("Content-Transfer-Encoding: binary");
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
} else {
header('Content-Disposition: attachment; filename="' . $filename . '"');
header('Content-Disposition: attachment; filename=""');
header("Content-Transfer-Encoding: binary");
header('Expires: 0');
header('Pragma: no-cache');
}
exit( serialize($data_store));