You are here

public function elFinderDrupal::GetContentDisposition in elFinder file manager 8.2

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 src/Controller/elFinderDrupal.php
Required to output file in browser when volume URL is not set Return array contains opened file pointer, root itself and required headers

File

src/Controller/elFinderDrupal.php, line 229
elFinder conenctor class

Class

elFinderDrupal
@file

Namespace

Drupal\elfinder\Controller

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;
  }
  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;
}