How to allow upload zip file in Media WordPress

By on April 6, 2022
function modify_upload_mimes ( $mimes_types ) {
    // add your extension to the mimes array as below
    $mimes_types['zip'] = 'application/zip';
    $mimes_types['gz'] = 'application/x-gzip';
    return $mimes_types;
}
add_filter( 'upload_mimes', 'modify_upload_mimes', 99 );

function add_allow_upload_extension_exception( $types, $file, $filename, $mimes ) {
    // Do basic extension validation and MIME mapping
    $wp_filetype = wp_check_filetype( $filename, $mimes );
    $ext         = $wp_filetype['ext'];
    $type        = $wp_filetype['type'];
    if( in_array( $ext, array( 'zip', 'gz' ) ) ) { // it allows zip files
        $types['ext'] = $ext;
        $types['type'] = $type;
    }
    return $types;
}
add_filter( 'wp_check_filetype_and_ext', 'add_allow_upload_extension_exception', 99, 4 );

WordPress version 4.7.1 ot greater, its added some extra security check for mime types. Just Add the follows code snippet in your active theme’s functions.php

About Thea

You must be logged in to post a comment Login