如何通过 php 或 javascript 编辑文件(将下载)的名称


How can I edit the name of a file (that will be downloaded) via php or javascript?

我正在尝试制作一个脚本,该脚本将根据用户在文本框中提交的内容重命名文件并下载它(我不希望它影响其他人的下载,所以我希望文件名仅基于他们提交的内容)。我不太了解Javascript,也不确定我是否会使用php或javscript来编辑它。我也不知道我会怎么做。有什么帮助吗?

像这样:

<?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;
}
?>