/**
* file download in MVC
*
* @author VECTOR Ann <ann@vector.cool>
* @since 1.0.1
*
* @param string $file 提供下載的檔案絕對路徑
* @param string $download_name 下載的檔名
* @return void
*/
function v_file_download($file,$download_name=''):void
{
if (is_file($file)) {
if($download_name=='')$download_name = date('Y_m_d',time()).".zip";
header_remove();
ob_end_clean();
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($download_name));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
readfile($file);
ob_end_flush();
exit;
}
}
如果文章對您很有幫助
請我喝杯咖啡吧
Bitcoin 比特幣錢包:
38ieWXhURt27br9XrDoCeo4eruzKyi8QKs
Post Views: 805