Notifications
Clear all

Script [Closed] Downloading custom file types from wpForo forum attachment

2 Posts
2 Users
0 Reactions
1,173 Views
Posts: 1
Topic starter
(@luminacommunityengagement)
New Member
Joined: 3 years ago

Hi there! I am setting up a forum for our website, and our users need to be able to upload a custom file type called an Analytica model (.ana).  Since .ana is a custom file type, I installed the WP plugin "File Upload Types" and added .ana files to the list of approved uploads. So the Analytica models (.ana) files can be uploaded to the forum, however when someone viewing the post then clicks on the uploaded model, it opens in a separate browser as a text file. 

My question is: how do I allow a user to download custom file types instead of having it open as a text file in a browser?  I realize this is partly a wpForo question, partly a File Upload Type question, but any help would be much appreciated! Alternatively, if someone could click on the attachment and have it automatically launch our Analytica program, that would be even better! Until our users can upload and download these Analytica models (.ana file types), our forum is somewhat useless!  

Note: In "File Upload Types" plugin, you are supposed to assign a custom MIME type, and using a File Type Checker website, it tells me that the MIME type is plain/html.  However this does not seem correct, because the .ana files are launched in the Analytica software/application.  

Thanks!
KM

1 Reply
Robert
Posts: 10590
Admin
(@robert)
Support Team
Joined: 9 years ago
Posted by: @luminacommunityengagement

Note: In "File Upload Types" plugin, you are supposed to assign a custom MIME type, and using a File Type Checker website, it tells me that the MIME type is plain/html.  However this does not seem correct, because the .ana files are launched in the Analytica software/application.  

I think the problem comes for registering the custom file type. How have you registered it and what MIME type have you set for .ana file format?

 

Posted by: @luminacommunityengagement

My question is: how do I allow a user to download custom file types instead of having it open as a text file in a browser?

Put this hook code in the functions.php file of your current active theme or use Code Snippets plugin for inserting custom hook code:

function wpforo_force_download_ana_files($text){
if( strpos($text, 'wpforo-default-attachment') !== FALSE && strpos($text, '.ana') !== FALSE ){
$text = preg_replace('|(class=\"wpforo-default-attachment\"[^><]+href=\"[^\]\[]+\.ana\")|s', '$1 download ', $text);
}
return $text;
}
add_filter('wpforo_content_after', 'wpforo_force_download_ana_files', 10);