是否可以让您的用户下载具有不同名称的文件?
例如,有一个名为“4324ffsd34.jpg”的文件。我希望人们通过download.php下载它,使用不同的名称(如“filetodownload.jpg”),而无需重命名原始文件。
答案 0 :(得分:55)
当然,请使用内容处理header
header('Content-Disposition: attachment; filename="filetodownload.jpg"');
如果您希望提供默认文件名,但不能自动下载,这似乎有效。
header('Content-Disposition: filename="filetodownload.jpg"');
答案 1 :(得分:23)
当然可以,尝试这样的事情:
$original_filename = '4324ffsd34.jpg';
$new_filename = 'my_new_filename_is_detailled.jpg';
// headers to send your file
header("Content-Type: application/jpeg");
header("Content-Length: " . filesize($original_filename));
header('Content-Disposition: attachment; filename="' . $new_filename . '"');
// upload the file to the user and quit
readfile($original_filename);
exit;
希望它有所帮助!
答案 2 :(得分:1)
<a href="4324ffsd34.jpg" download="filetodownload">Download</a>
答案 3 :(得分:0)
以上没有错,但我不得不补充:
ob_clean();
flush();
否则我无法打开下载jpg / png文件