方案如下:
设置header头
public function download($path)
{
if(is_file($path) && file_exesites($path,$url)){
$length = filesize($path);
$type = mime_content_type($path);
$showname = ltrim(strrchr($path,'/'),'/');
$pinjie = strstr($showname,'.');
$downloadname = $path;
// header头设置 图片下载
header( 'Expires: 0' );
header( 'Cache-Control: must-revalidate, post-check=0, pre-check=0' );
header( 'Cache-Control: private', false );
header( 'Content-Description:File Transfer' );
header( 'Content-Type: image/jpeg');
header('Content-Disposition: attachment; filename='.basename($downloadname));
Header("Accept-Ranges: bytes");
if (preg_match('/MSIE/', $_SERVER['HTTP_USER_AGENT'])) { //IE
header('Content-Disposition: attachment; filename="' . rawurlencode('$url'.$downloadname) . '"');
} else {
header('Content-Disposition: attachment; filename="' . $downloadname . '"');
}
readfile($path);
fclose($path);
exit;
}else{
$this->error('您要下载的文件不存在或已丢失');
}
}