You are here

public function elFinderDrupal::GetContentDisposition in elFinder file manager 6.2

Same name and namespace in other branches
  1. 7.3 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

1 call 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

File

inc/elfinder.drupal.inc, line 198

Class

elFinderDrupal

Code

public 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;
  }
  else {
    if (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;
}