php輸出服務器文件下載到瀏覽器

if (!function_exists('output_for_download')) {
    /**
     * 下載文件到瀏覽器
     *
     * @param string $filename 文件路徑
     * @param array  $title    輸出的文件名
     * @return void
     */
    function output_for_download($filename, $title)
    {
        $file  =  fopen($filename, "rb");
        Header( "Content-type:  application/octet-stream ");
        Header( "Accept-Ranges:  bytes ");
        Header( "Content-Disposition:  attachment;  filename= $title");
        while (!feof($file)) {
            echo fread($file, 8192);
            ob_flush();
            flush();
        }
        fclose($file);
    }
}
相關文章
相關標籤/搜索