I have some images used for the avatars of the users on my website, for example http://drksde.tk/images/avatar-Luxie.jpeg I want to add a link that allow the users to download the avatar image, when someone click in the link a Save As dialog should appear.
Now the problem is that the picture is not downloaded properly, but the dialog appears, here is the link to download the avatar, and the code:
<?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;
?>