I am trying to make a script that will rename a file based off what a user submitted in a textbox and download it (I do not want it to affect other people's downloads though, so I want the name of the file to only be based off what they submitted ). I do not know much Javascript and am not sure if I would use php or javscript to edit it. Also I have no clue how I would do it. Any help?
Asked
Active
Viewed 29 times
-2
-
add a download attrib to a normal tag to specify a filename and force a download – dandavis Nov 25 '14 at 22:48
1 Answers
1
something like so:
<?php
$file = 'monkey.gif';
$new_file_name='monkey_'.$_POST['colour'].'.gif';
if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.$new_file_name);
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
readfile($file);
exit;
}
?>