Whenever i run this script , i get a corrupted file .Downloading is happening but i get a corrupted file .let it be a zip file ,img file ,only txt files are working good.Plz help
<?php
function download($file){
$file="1.jpg";
$dir = './files/';
$path = $dir.$file;
if(!file_exists($path)){
die('Error');
}else{
header('Content-Disposition: attachment; filename='.basename($path));
header('Content-Type: image/jpeg');
header('Content-Transfer-Encoding: binary');
header('Content-Length: ' . filesize($path));
readfile($path);
}
}
download("1.jpg");
?>