PHP Force download is downloading an empty file

    /**
     * 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;
    	}
    }
READ  jQuery & CSS easings 過渡動畫緩動函式-速查表

發表迴響

這個網站採用 Akismet 服務減少垃圾留言。進一步瞭解 Akismet 如何處理網站訪客的留言資料