Files open in browser window

13 years 4 weeks ago #159210 by drdehart
Files open in browser window was created by drdehart
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?

Please Log in to join the conversation.

13 years 4 weeks ago - 13 years 4 weeks ago #159224 by krileon
Replied by krileon on topic Re: Files open in browser window
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 Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions 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 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 CST to 4:00 PM CST. 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.

Please Log in to join the conversation.

Moderators: beatnantkrileon
Time to create page: 0.183 seconds

Facebook Twitter LinkedIn