Add limited file size upload (for vendor)

We're shifting our Forum based support to a more dedicated support system!

We'll be closing our Forum support from 10th June, 2020 and move to Email Support assistance.

  • If you are a WCFM premium add-ons user, contact us- here
  • Want to know more before buying our add-ons? Send Pre sale queries- here
  • If you are a WCFM free user, please open a support ticket at WordPress.org
  • For WCFM App related queries, reach us- here
From now the forum will be read-only!

Multi Vendor Marketplace Plugin | WCFM Marketplace Forums WCFM – Feature Request Add limited file size upload (for vendor)

Viewing 3 reply threads
  • Author
    Posts
    • #56763
      Hamid
      Guest

      Please Add limited file size upload for vendor..

      I will be your regular customer if you have more restrictive settings for uploading

      thanks

    • #56773
      WCFM Forum
      Keymaster

      Hi,

      Here is code snippet, you may add this to your child theme’s functions.php to restrict vendors from uploading restricted dimension files-

      function wcfm_max_image_size( $file ) {
       
        $img     = getimagesize($file['tmp_name']);
      	$minimum = array( 'min_width' => '600', 'max_width' => '1200', 'min_height' => '600', 'max_height' => '1200' );
      	$width   = $img[0];
      	$height  = $img[1];
      
      	if ($width > $minimum['max_width'] )
      		return array("error"=>"Image dimensions are too large. Maximum width is {$minimum['max_width']}px. Uploaded image width is $width px");
      	elseif ($width < $minimum['min_width'] )
      		return array("error"=>"Image dimensions are too small. Minimum width is {$minimum['min_width']}px. Uploaded image width is $width px");
      	elseif ($height >  $minimum['max_height'])
      		return array("error"=>"Image dimensions are too large. Maximum height is {$minimum['max_height']}px. Uploaded image height is $height px");
      	elseif ($height <  $minimum['min_height'])
      		return array("error"=>"Image dimensions are too small. Minimum height is {$minimum['min_height']}px. Uploaded image height is $height px");
      	else
      		return $file; 
        
        return $file;
      }
      add_filter( 'wp_handle_upload_prefilter', 'wcfm_max_image_size' );

      You may tweak this code to add file size restriction as well.

      Thank You

    • #56784
      Hamid
      Guest

      Thanks

      I mean the file size (image file, Zip file or …)
      Example: 50 MB

      I have a file sales store..

    • #56786
      WCFM Forum
      Keymaster

      Hi,

      Please use this code, it will restrict image/file upload more than 1 MB size –

      function wcfm_max_image_file_size( $file ) {
        $img_size = filesize($file['tmp_name']);
      	$maximum  = 1*1024*1024;
      	if ( $img_size > $maximum ) {
      		$img_size = wc_format_decimal( ($img_size/1024)/1024, 2 );
      		return array( "name" => "", "error"=>"Image sizse is too large. Maximum allowed size 1 MB. Uploaded image size is {$img_size} MB" );
      	}
      	return $file;
      }
      add_filter( 'wp_handle_upload_prefilter', 'wcfm_max_image_file_size' );

      Thank You

Viewing 3 reply threads
  • The topic ‘Add limited file size upload (for vendor)’ is closed to new replies.