How to allow WordPress to upload Flash SWF files

filetypeerrorSome banner ads still use Flash SWF format, unfortunately Flash SWF is one of few format that has not been permitted in WordPress for security reason. WordPress generate error like this“Sorry, this file type is not permitted for security reasons.“ when we try to upload Flash SWF files in WordPress

Previously, we wrote a post to lifted this restriction in WordPress that allow users to upload file types, however this method don’t work when we added SWF to Upload file types settings in WordPress Multisite/Network without telling WordPress to allow Flash SWF file type first

Add following code to theme functions.php file to allow Flash SWF uploaded to the site

/* allow upload flash */
add_filter('upload_mimes', 'pixert_upload_swf');
function pixert_upload_swf($existing_mimes){
$existing_mimes['swf'] = 'text/swf'; //allow swf files
return $existing_mimes;
}
/* allow upload flash */

or

function pixert_allow_swf($mimes) {
	if ( function_exists( 'current_user_can' ) )
		$unfiltered = $user ? user_can( $user, 'unfiltered_html' ) : current_user_can( 'unfiltered_html' );
	if ( !empty( $unfiltered ) ) {
		$mimes['swf'] = 'application/x-shockwave-flash';
	}
	return $mimes;
}
add_filter('upload_mimes','pixert_allow_swf');

After that, we could add SWF to Upload file types settings in WordPress Multisite/Network


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: