0

I am trying to allow files that are within the /sites/default/files/private/ directory to available to users with correct role and this is working correctly within all browsers (including IE9) except for the IE8 browser. It does not appear to be a particular file type since it does not work with either .pdf's or .doc's extension. It their something special that I need to do to the "mime type" so that IE8 will successfully download these files? I have listed below hook_file_download which determines when a requested file download is allowed based on a combination of the page $url and the requesting users role and I highlighted in bold the bottom of the function where it determines the mime type that is returned.

function atf_retirees_file_download($uri) {
  $user = $GLOBALS['user'];
  $roles = $user->roles;
  $pos_inside_atf_alias = stripos($uri, '/inside-atf/');
  $pos_nibin_alias = stripos($uri, '/nibin-user-area/');
  if (($pos_inside_atf_alias === false && $pos_nibin_alias === false) || ($pos_inside_atf_alias !== false && !(in_array('ATF Retirees', $roles) || in_array('administrator', $roles))) || ($pos_nibin_alias !== false && !(in_array('NIBIN User Area', $roles) || in_array('administrator', $roles)))) {
    return -1;  
  } else {
    **$mime_type = file_get_mimetype($uri);
    return array('Content-Type' => $mime_type);**
  }
}
0

I found that if I added "'Cache-Control' => 'private, must-revalidate'" to the returned array within hook_file_download that the file also downloads for IE8 (see below section).

$mime_type = file_get_mimetype($uri);
return array('Content-Type' => $mime_type, 'Cache-Control' => 'private, must-revalidate');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.