文件下载方法

public function download_file($file) {
  if (file_exists ( $file ))
{
   $this_base_file = basename ( $file );
   header ( "Content-type:application/octet-stream" );
   header ( "Accept-Ranges: bytes" );
   header ( "Accept-Length: " . filesize ( $file ) );
   header ( "Content-Disposition: attachment; filename="" . $this_base_file . """ );
   readfile ( $file );
  }
}

原文地址:https://www.cnblogs.com/xlz307/p/3425375.html