You are here

function filebrowser_filebrowser_download_manager_process in Filebrowser 8

Same name and namespace in other branches
  1. 7.4 filebrowser.module \filebrowser_filebrowser_download_manager_process()
  2. 7.2 filebrowser.module \filebrowser_filebrowser_download_manager_process()
  3. 7.3 filebrowser.module \filebrowser_filebrowser_download_manager_process()

hook_filebrowser_download_manager_process implementation.

File

./filebrowser.module, line 849
Validates file path input on node form

Code

function filebrowser_filebrowser_download_manager_process($delta = NULL, $file = NULL, $filename = NULL) {
  switch ($delta) {
    case 'public':
      $web_root = getcwd();
      if (strpos($web_root, $file) === 0) {
        $target = substr($file, strlen($web_root));
      }
      else {
        $target = $file;
      }
      header("Location: " . url(trim($target, '/'), array(
        'absolute' => TRUE,
      )));
      return TRUE;
    case 'private':
      header('Content-Description: File Transfer');
      header("Cache-Control: public, must-revalidate, max-age=0");

      // HTTP/1.1
      header("Pragma: public");
      header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");

      // Date in the past
      header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
      header("Content-Type: " . file_get_mimetype($filename));
      header("Content-Transfer-Encoding: binary");
      header("Content-Length: " . filesize($file));
      if (stristr("MSIE", getenv("HTTP_USER_AGENT")) || stristr("Internet Explorer", getenv("HTTP_USER_AGENT"))) {
        header('Content-Disposition: inline; filename="' . mb_convert_encoding(_filebrowser_safe_basename($filename), "ISO-8859-2", "UTF-8") . '";');
      }
      else {
        header('Content-Disposition: inline; filename="' . _filebrowser_safe_basename($filename) . '";');
      }
      $block_size = 4096;
      $buffer = '';
      $handle = fopen($file, 'rb');
      drupal_set_time_limit(0);
      if ($handle !== FALSE) {
        while (!feof($handle)) {
          $buffer = fgets($handle, $block_size);
          echo $buffer;
          ob_flush();
          flush();
        }
        fclose($handle);
      }
      return TRUE;
  }
}