嗨,有什么办法可以给用户不同的文件名称,我有在我的服务器
for example
我有文件在我的服务器有md5名称,如
33e65007ba9387583d4902e5497fc9ac.mp3
我需要当用户点击下载此文件时,将下载文件的名称更改为something.mp3
这个更改只是在用户文件下载时进行的它不会影响服务器上的文件名
More detail :
服务器文件名为:
33e65007ba9387583d4902e5497fc9ac.mp3
下载
something.mp3
with后的用户文件名
我怎么做这件事?用PHP ?
可以将文件名存储在$name中,将文件内容存储在$content中。然后,使用以下代码下载文件:
header('Content-Description: File Transfer');
header("Content-type: application/force-download");
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=' . $name);
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . strlen($content));
ob_clean();
flush();
echo $content;
我通过将下载的PHP文件更改为
解决了这个问题<?php
$file = $_GET['file'];
header ("Content-type: octet/stream");
header ("Content-disposition: attachment; filename=".$file.";");
header("Content-Length: ".filesize($file));
readfile($file);
exit;
?>