WordPress.org

Ready to get started?Download WordPress

Forums

Frontend Uploader
[resolved] Audio file Support? (8 posts)

  1. designxxl
    Member
    Posted 1 year ago #

    Is there a way to add audio file support? The mime-types support in "Other Notes" is very unclear on this as well. Thanks in advance.

    http://wordpress.org/extend/plugins/frontend-uploader/

  2. Rinat Khaziev
    Member
    Plugin Author

    Posted 1 year ago #

    Put this in your functions.php. This is an example for mp3 and wav.
    Here we have array of allowed mime types. Array key would be file extension, and array value is a mime type itself.

    add_filter( 'fu_allowed_mime_types', 'my_fu_allowed_mime_types' );
    function my_fu_allowed_mime_types( $mime_types ) {
        $mime_types['mp3'] = 'audio/mpeg';
        $mime_types['wav'] = 'audio/wav';
        return $mime_types;
    }

    The thing is sometimes one file might have different mime-types depending on server set up, so it might be a trial and error thing until you find the mime that works for you.
    Does this make it clearer?

  3. designxxl
    Member
    Posted 1 year ago #

    Im still getting this error :(

    There was an error with your submission
    This kind of file is not allowed. Please, try again selecting other file.:
    Respect.mp3

  4. Rinat Khaziev
    Member
    Plugin Author

    Posted 1 year ago #

    Ok, so here's the thing, these are existing mime types for mp3:
    audio/mpeg, audio/x-mpeg, audio/mp3, audio/x-mp3, audio/mpeg3, audio/x-mpeg3, audio/mpg, audio/x-mpg, audio/x-mpegaudio
    If you put everything from this list into the filter it should work. Check out the sample below.

    add_filter( 'fu_allowed_mime_types', 'my_fu_allowed_mime_types' );
    function my_fu_allowed_mime_types( $mime_types ) {
        // Array keys should be unique
        // To include all mime-types we use this workaround
        // Part after | could be anything as long as it's unique
        $mime_types['mp3|mp3-am'] = 'audio/mpeg';
        $mime_types['mp3|mp3-xam'] = 'audio/x-mpeg';
        // Include the rest of mp3 mimes
    
        $mime_types['wav'] = 'audio/wav';
        return $mime_types;
    }

    Let me know if it works. Even if it works :)

  5. designxxl
    Member
    Posted 1 year ago #

    Unbelievable...i tried this:

    add_filter( 'fu_allowed_mime_types', 'my_fu_allowed_mime_types' );
    function my_fu_allowed_mime_types( $mime_types ) {
        // Array keys should be unique
        // To include all mime-types we use this workaround
        // Part after | could be anything as long as it's unique
        $mime_types['mp3|mp3-am'] = 'audio/mpeg';
        $mime_types['mp3|mp3-xam'] = 'audio/x-mpeg';
        $mime_types['mp3|mp3-am'] = 'audio/x-mpeg-3';
        $mime_types['mp3|mp3-xam'] = 'audio/x-mpeg-3';
    
        // Include the rest of mp3 mimes
    $mime_types['mp3|mp3-am'] = 'audio/mpeg';
    $mime_types['mp3|mp3-am'] = 'audio/x-mpeg';
    $mime_types['mp3|mp3-am'] = 'audio/mp3';
    $mime_types['mp3|mp3-am'] = 'audio/x-mp3';
    $mime_types['mp3|mp3-am'] = 'audio/mpeg3';
    $mime_types['mp3|mp3-am'] = 'audio/x-mpeg3';
    $mime_types['mp3|mp3-am'] = 'audio/mpg';
    $mime_types['mp3|mp3-am'] = 'audio/x-mpg';
    $mime_types['mp3|mp3-am'] = 'audio/x-mpegaudio';
    
        $mime_types['wav'] = 'audio/wav';
        return $mime_types;
    }

    And still nothing... impossible! :'(

  6. Rinat Khaziev
    Member
    Plugin Author

    Posted 1 year ago #

    Hey designxxl,

    I wrote this snippet for you, and tested it, and was able to upload mp3

    add_filter( 'fu_allowed_mime_types', 'my_fu_allowed_mime_types' );
    function my_fu_allowed_mime_types( $mime_types ) {
        // Array keys should be unique
        // To include all mime-types we use this workaround
        // Part after | could be anything as long as it's unique
    	$mp3_mimes = array( 'audio/mpeg', 'audio/x-mpeg', 'audio/mp3', 'audio/x-mp3', 'audio/mpeg3', 'audio/x-mpeg3', 'audio/mpg', 'audio/x-mpg', 'audio/x-mpegaudio' );
    	foreach( $mp3_mimes as $mp3_mime ) {
    		$mime = $mp3_mime;
    		preg_replace("/[^0-9a-zA-Z ]/", "", $mp3_mime );
    		$mime_types['mp3|mp3_' . $mp3_mime ] = $mime;
    	}
    
        $mime_types['wav'] = 'audio/wav';
        return $mime_types;
    }
  7. designxxl
    Member
    Posted 1 year ago #

    You sir are AWESOMEEEE!!!!!! :) Thank you greatly!

  8. Rinat Khaziev
    Member
    Plugin Author

    Posted 1 year ago #

    You're welcome, don't forget to rate the plugin ;)
    http://wordpress.org/support/view/plugin-reviews/frontend-uploader

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic