예제 #1
0
 /**
  * 履歴ファイルダウンロード
  *
  * @param none
  *
  * @return none
  */
 function download_history_file($file_history_id, $mode = '')
 {
     $file_history_row = ACSFileHistory::get_file_history_row($file_history_id);
     // ファイルパス
     if ($mode == 'thumb') {
         $file_path = $file_history_row['thumbnail_server_file_name'];
     } else {
         $file_path = $file_history_row['server_file_name'];
     }
     // ファイルが読み込みできない場合
     if (!is_readable(ACS_FOLDER_DIR . $file_path)) {
         header("Cache-Control: public, max-age=0");
         header("Pragma:");
         echo "Not Found";
         return;
     }
     // ダウンロードファイル名
     //		$download_file_name = mb_convert_encoding($this->get_display_file_name(), mb_http_output());
     $download_file_name = $this->get_display_file_name();
     // Content-type
     $content_type = $file_history_row['mime_type'];
     if ($content_type == '') {
         $content_type = 'application/octet-stream';
     }
     // charset (textの場合)
     if (preg_match('/text/', $content_type)) {
         $str = implode('', file(ACS_FOLDER_DIR . $file_path));
         $encoding = mb_detect_encoding($str, 'auto');
         if ($encoding == 'ASCII' && mb_http_output() != 'pass') {
             $content_type .= "; charset=" . mb_preferred_mime_name(mb_http_output());
         } else {
             $content_type .= "; charset=" . mb_preferred_mime_name($encoding);
         }
     }
     // action: inline(ブラウザ内表示), attachment(ダウンロードダイアログ)
     //if (preg_match('/text|image/', $content_type)) {
     if (preg_match('/image/', $file_history_row['mime_type']) || preg_match('/text/', $file_history_row['mime_type'])) {
         $action = 'inline';
     } else {
         $action = 'attachment';
     }
     // HTTPヘッダを吐く (action: inline, attachment)
     //		header("Content-disposition: $action; filename=\"$download_file_name\"");
     header("Content-disposition: {$action}; attachment; filename=\"" . ACSFile::get_download_name($download_file_name) . '"');
     header("Content-type: {$content_type}");
     // output_bufferingを無効にする
     mb_http_output('pass');
     if ($mode == 'thumb') {
         header("Cache-Control: public, max-age=1800");
         header("Pragma:");
     } else {
         header("Cache-Control: public, max-age=0");
         header("Pragma:");
     }
     // ファイルを読み出す
     readfile(ACS_FOLDER_DIR . $file_path);
 }