public function download(){
$equipmentInfoModel = new EquipmentInfoModel();
$file_name = $equipmentInfoModel->where('id', input('id'))->column('qrcode_img');
$file_dir = ROOT_PATH.'public'.implode($file_name);
if (file_exists($file_dir)){
$file = fopen($file_dir, 'r');
// 输入文件标签
\header('Content-type: application/octet-stream');
\header('Accept-Ranges: bytes');
\header('Accept-Length: '.filesize($file_dir));
\header('Content-Disposition: attachment; filename='.implode($file_name));
ob_clean();
flush();
echo fread($file, filesize($file_dir));
fclose($file);
exit();
}else{
$equipmentInfoModel->update(['id' => input('id'), 'qrcode_img' => '']);
$this->error('文件已被删除,下载失败, 请重新生成二维码');
}
}
网友评论