You are here

function webform_file_download in Webform 5.2

Same name and namespace in other branches
  1. 8.5 webform.module \webform_file_download()
  2. 5 webform.module \webform_file_download()
  3. 6.3 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()

Implementation of hook_file_download().

Only allow users with view webform submissions to download files.

File

./webform.module, line 303

Code

function webform_file_download($file) {
  $file = file_check_location(file_directory_path() . '/' . $file, file_directory_path() . '/webform/');
  if ($file && user_access('access 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;
  }
}