Example #1
0
File: php.php Project: xpd1437/swap
 /**
  * 把 $file 的文件内容当成 http 响应的内容体,并把 http 响应发送出去,供客户端下载(显示的下载文件名为 $filename_ext)。
  */
 public static function send_file($file, $filename_ext = '')
 {
     if ($filename_ext === '') {
         $filename_ext = basename($file);
     }
     if (visitor::is_ie()) {
         $filename_ext = urlencode($filename_ext);
         $content_type = 'application/force-download';
     } else {
         $content_type = 'application/octet-stream';
     }
     visitor::set_header('Content-Disposition', 'attachment; filename=' . $filename_ext);
     visitor::set_header('Content-Transfer-Encoding', 'binary');
     $content = file_get_contents($file);
     visitor::set_header('Content-Length', strlen($content));
     self::send($content, $content_type);
 }