| 
Welcome, Guest
  • Page:
  • 1

TOPIC: Files open in browser window

Files open in browser window 2 years 1 month ago #159210

  • drdehart
  • drdehart
  • OFFLINE
  • Platinum Boarder
    Platinum Boarder
  • Posts: 367
  • Karma: 1
When trying to download a text file from the new files plugin for groupjive the file is opened in a browser window instead of showing the download box. We contacted our hosting company and have been told that in order to prevent file to open in a browser and open a download dialog, we have to set the content type at the application level. So is not something handled by the server but from php "Content-Transfer-Encoding" and "Content-Type".

This is a script that worked for us in a previous situation:

<?php
function Mext2mime($ext) {
$map = array(
'jpg' => 'image/jpeg',
'jpeg' => 'image/jpeg',
'gif' => 'image/gif',
'png' => 'image/png',
'zip' => 'application/zip',
'txt' => 'text/plain',
'doc' => 'application/msword',
'docx' => 'application/msword',
'gz' => 'application/x-gzip',
'tgz' => 'application/x-compressed-tar',
'pdf' => 'application/pdf'
);

if (isset($map[$ext])) {
return $map[$ext];
}
// return 'x-extension/' . $ext;
// return 'application/octet-stream';
return 'application/force-download';
}

header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=\"".$_REQUEST."\"");
header("Content-Type: ".Mext2mime($_REQUEST));
header("Content-Transfer-Encoding: binary");
header("Content-Length:".$_REQUEST);

?>

Is it possible to include this feature on new gj release?
The administrator has disabled public write access.

Re: Files open in browser window 2 years 1 month ago #159224

  • krileon
  • krileon
  • OFFLINE
  • Moderator
    Moderator
  • Posts: 31499
  • Karma: 903
Files are a direct URL in the same manner the file field works. No plans to change otherwise at this time. Certainly no plans to modify headers in such a manner as well. File integration is open source however and you're free to make additions. All browsers I've tested (IE7, IE8, FF, Chrome) in the direct URL functions fine for serving downloads (except in scenarios where the browser can render the download).
Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Tutorials + Search the forums
CB links: Documentation - Tutorials - Templates - CBSubs - Hosting - Forge - Incubator - GroupJive
--
If you are a Advanced, Professional, Developer, or CBSubs subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Advanced, Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM EST to 4:00 PM EST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.
--
If you use Community Builder, please post a rating and a review at the Joomla! Extensions Directory.
Last Edit: 2 years 1 month ago by krileon.
The administrator has disabled public write access.
  • Page:
  • 1
Time to create page: 0.189 seconds