我在我的网站上有一些用于用户头像的图像,例如http://drksde.tk/images/avatar-Luxie.jpeg 我想添加一个链接,允许用户下载头像图像,当有人单击链接,应出现“另存为”对话框。
现在问题是图片没有正常下载,但是出现了对话框,下面是头像下载链接,代码:
<?php
$username = $_GET['username'];
$size = $_GET['size'];
$ext = $_GET['ext'];
$border = $_GET['border'];
$basename = basename($_SERVER['REQUEST_URI']);
if(!isset($size)) { $size = 'small'; }
if(!isset($ext)) { $ext = 'jpeg'; }
if(!isset($border)) { $border = 'true'; }
$file = 'avatar-'.$size.'-'.$username.'.'.$ext;
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.$basename);
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
#header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
exit;
?>