You need to get the mime type and file size, and then set the correct headers before sending the file. Try the following:
function sendFile($file) {
$finfo = finfo_open(FILEINFO_MIME_TYPE);
header('Content-type: ' . finfo_file($finfo, $file));
header('Content-length: ' . filesize($file));
$filename = basename($file);
header("Content-Disposition: attachment; filename='$filename'");
fpassthru($file);
finfo_close($finfo);
}
source
share