songohan
Posts: 89
|
| Posted: 07/02/2009, 3:57 PM |
|
Thanks to Tangels code from 2005 (http://forums.yessoftware.com/posts.php?post_id=56563) I resolved how to keep timestamp in filename on server and still offer file with original name to user for download.
I added following code to After Initialise event on page where where I have link to file. Link points to same page and adds "filename" parameter to URL.
Adding this code to Before Show also works but if Cancel button is pressed in "Save file" dialog box browser gets stuck for some time and content of file is printed to page (Firefox).
if (CCGetFromGet('file') != ""){
$dir ="user_files/";
$file_name = CCGetFromGet('file');
$file = ($dir.$file_name);
$original_filename = CCGetOriginalFileName($file_name);
header("Content-Length: " . filesize($file));
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"$original_filename\"");
header("Content-Transfer-Encoding: binary");
readfile($file);
}
|