Example #1
0
 /**
  * attachmentで出力する
  * @param File $file 出力するファイル
  */
 public static function attach(File $file)
 {
     Log::disable_display();
     if (is_file($file->fullname()) || $file->value() !== null) {
         if ($file->update() > 0) {
             if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && $file->update() <= strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
                 self::status_header(304);
                 exit;
             }
             header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $file->update()) . ' GMT');
         }
         header(sprintf('Content-Type: ' . $file->mime() . '; name=%s', $file->name()));
         header(sprintf('Content-Disposition: attachment; filename=%s', $file->name()));
         if ($file->size() > 0) {
             header(sprintf('Content-length: %u', $file->size()));
         }
         $file->output();
     }
     self::status_header(404);
     exit;
 }