WordPress accepting other formats?

I want to post objects which are not an Image/Video/Media in Wordpress, and I want to keep their original file format without renaming them to TXT extension, so that WordPress will accept the file in the post is this possible ?

I’ve searched for an answer and all I found was one tutorial where the author posted a PDF file and it worked but what about foreign file formats? No add-on, nothing.

You can… Just use the add media option, and make sure the format says all formats. I just uploaded a Word doc, linked and viewed it on a test post. It kept the docx format and showed up in my media library too.

I tried that before writing the post, I get the following error;

Sorry, this file type is not permitted for security reasons.

ok what type of file are you attempting?

PSD and a few other proprietary software.

Oh I see. Read the following link to fix that: Upload mimes

$existing_mimes[‘doc’] = ‘application/msword’;

I add the custom mime types with commas separating ? I’m going to try this later on :slight_smile:

No, I believe you would do


$existing_mines['psd'] = 'application/photoshop';

I am guessing on the photoshop bit.

At this point WordPress is not loading:

add_filter('###,### 'programA,programB');
function custom_upload_mimes ( $existing_mimes=array() ) {
 
// Add file extension 'extension' with mime type 'mime/type'
$existing_mimes['###'] = 'application/<program-name>';
$existing_mines['###'] = 'application/<program-name>'; 
 
// add as many as you like e.g. 

$existing_mimes['doc'] = 'application/msword'; 

// remove items here if desired ...
 
// and return the new full result
return $existing_mimes;

 
}

I placed this PHP code within Functions.PHP and WordPress Admin Login doesn’t load. The hashes represent the program extension.

You are missing a quote, so

add_filter('###,### 'programA,programB')

should be

add_filter('###,###', 'programA,programB')

But that does not look like the sample code at all

It’s not the sample code, I replaced parts of it. Regardless it doesn’t work. Arrrghhh how do you get this to work !!!

Try this. Don’t alter the add_filter line and only add new mimes where indicated.

add_filter('upload_mimes', 'custom_upload_mimes');

function custom_upload_mimes ( $existing_mimes=array() ) {

// add new mimes below
$existing_mimes['psd'] = 'application/photoshop'; 
$existing_mimes['doc'] = 'application/msword';

return $existing_mimes;
 
}

That didn’t work either.

Works fine here. What was the result? Wordpress not loading? Security warning?

I know you tweaked the code. However the code you provided earlier is invalid. The code provided by Vic is the proper way of coding it, and should work. Where are you putting Vic’s code?

The result was wordpress admin not logging in !

Part of it may be saying the correct type, I found


'mov|qt|3gp|3gpp' => 'video/quicktime',

which allows .mov, .qt etc, you see how it says video versus application? I am thinking it may not like that.

I tried placing this

‘SWK’ => ‘image/program’,
(fictitious extension, as far as I know)

here:

if ( !$mimes ) {
// Accepted MIME types are set here as PCRE unless provided.
$mimes = apply_filters( ‘upload_mimes’, array(
‘jpg|jpeg|jpe’ => ‘image/jpeg’,

Didn’t work, Victors code probably does work but where does it get placed ?

Put the code at the very bottom of the current theme’s functions.php file

It appears to have worked :slight_smile:
Thanx for the tip, I forgot their was a functions.php for each theme :slight_smile: