使用这样的代码
$path="uploads/";
$actualfilename=$path.$filename;
$fakefilename="downloadfile.pdf";
if($typeofview=="download") {
@readfile($actualfilename);
header('Content-type: application/pdf');
header('Content-Disposition: attachment; filename="' . $fakefilename . '"');
header('Content-Transfer-Encoding: binary');
header('Content-Length: ' . filesize($actualfilename));
header('Accept-Ranges: bytes');
exit;
将其添加到.htaccess文件中
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule fakefile.php(.*)$orignalfile.php?$1 [L,QSA]