BuddyDev

Search

Limit file upload size in MediaPress

  • Participant
    Level: Initiated
    Posts: 14
    Cordial on #51137

    How can I set a different file upload size limit for MediaPress?

    I mean file size limit on media item being uploaded. For example, I want to be able to set file upload limit of 1.5MB.

    Then if user uploads an image, video, music or document of 2MB, the file should not be accepted, and they should get an error message saying “file size exceeded. Upload size is 1.5MB”.

    Features should include ability to set different file upload limit for different media files for example:

    1. image upload limit is 1MB
    2. music upload limit is 5MB
    3. video upload limit is 10MB
    4. document upload limit is 500KB

    How do I achieve such with MediaPress?

    Regards.

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3115
    Ravi on #51158

    Hello Cordial,

    Thank you for posting. I will look at it today and will update you soon.

    Regards
    Ravi

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3115
    Ravi on #51172

    Hello Cordial,

    Please upgrade to the latest version of MediaPress i.e. 1.5.9 and use the following code:

    
    add_filter( 'mpp_upload_prefilter', function ( $file ) {
    
    	if ( ! isset( $file['type'] ) || ! isset( $file['size'] ) ) {
    		return $file;
    	}
    
    	// 1 MB in byte.
    	$mb_in_byte = 1 * 1000000;
    
    	if ( strstr( $file['type'], 'video/' ) && $file['size'] > 10 * $mb_in_byte ) {
    		$file['error'] = __( 'video upload limit is 10MB' );
    	} elseif ( strstr( $file['type'], 'image/' ) && $file['size'] > 1 * $mb_in_byte ) {
    		$file['error'] = __( 'image upload limit is 1MB' );
    	}
    
    	return $file;
    } );
    
    

    Please give it a try

    Regards
    Ravi

You must be logged in to reply to this topic.

This topic is: not resolved