You are here

function webform_file_download in Webform 6.3

Same name and namespace in other branches
  1. 8.5 webform.module \webform_file_download()
  2. 5.2 webform.module \webform_file_download()
  3. 5 webform.module \webform_file_download()
  4. 6.2 webform.module \webform_file_download()
  5. 7.4 webform.module \webform_file_download()
  6. 7.3 webform.module \webform_file_download()
  7. 6.x webform.module \webform_file_download()

Implements hook_file_download().

Only allow users with view webform submissions to download files.

File

./webform.module, line 917

Code

function webform_file_download($file) {
  global $user;

  // If the Webform directory doesn't exist, don't attempt to deliver a file.
  $webform_directory = file_directory_path() . '/webform/';
  if (!is_dir($webform_directory)) {
    return;
  }
  $file = file_check_location(file_directory_path() . '/' . $file, $webform_directory);
  if ($file && (user_access('access all webform results') || user_access('access own webform results'))) {
    $info = image_get_info(file_create_path($file));
    if (isset($info['mime_type'])) {
      $headers = array(
        'Content-type: ' . $info['mime_type'],
      );
    }
    else {
      $headers = array(
        'Content-type: force-download',
        'Content-disposition: attachment',
      );
    }
    return $headers;
  }
}