You are here

public static function elFinderDrupal::GetContentDisposition in elFinder file manager 7.3

Same name and namespace in other branches
  1. 6.2 inc/elfinder.drupal.inc \elFinderDrupal::GetContentDisposition()
  2. 7.2 inc/elfinder.drupal.inc \elFinderDrupal::GetContentDisposition()

Generating Content-Disposition HTTP header

@author Dmitry (dio) Levashov, Alexey Sukhotin

Parameters

string $file Filename:

string $filemime MIME Type:

bool $download Disposition type (true = download file, false = open file in browser):

Return value

string

2 calls to elFinderDrupal::GetContentDisposition()
elFinderDrupal::file in inc/elfinder.drupal.inc
Required to output file in browser when volume URL is not set Return array contains opened file pointer, root itself and required headers
elfinder_file_download in ./elfinder.module

File

inc/elfinder.drupal.inc, line 213
elFinder conenctor class

Class

elFinderDrupal
@file

Code

public static function GetContentDisposition($file, $filemime, $download = FALSE) {
  $disp = '';
  $filename = $file;
  $ua = $_SERVER["HTTP_USER_AGENT"];
  $mime = $filemime;
  if ($download) {
    $disp = 'attachment';
    $mime = 'application/octet-stream';
  }
  else {
    $disp = preg_match('/^(image|text)/i', $mime) || $mime == 'application/x-shockwave-flash' ? 'inline' : 'attachment';
  }
  $disp .= '; ';
  if (preg_match("/MSIE ([0-9]{1,}[\\.0-9]{0,})/", $ua)) {
    $filename = rawurlencode($filename);
    $filename = str_replace("+", "%20", $filename);

    //$filename = str_replace(" ", "%20", $filename);
    $disp .= "filename=" . $filename;
  }
  elseif (preg_match("/Firefox\\/(\\d+)/", $ua, $m)) {
    if ($m[1] >= 8) {
      $disp .= "filename*=?UTF-8''" . rawurlencode($filename);
    }
    else {
      $disp .= "filename*=\"?UTF-8''" . rawurlencode($filename) . "\";";
    }
  }
  else {
    $disp .= "filename=" . $filename;
  }
  return $disp;
}