Multi Vendor Marketplace Plugin | WCFM Marketplace › Forums › WCFM – Feature Request › Add limited file size upload (for vendor)
- This topic has 3 replies, 2 voices, and was last updated 4 years, 11 months ago by WCFM Forum.
Viewing 3 reply threads
- AuthorPosts
- April 8, 2019 at 6:12 am #56763HamidGuest
Please Add limited file size upload for vendor..
I will be your regular customer if you have more restrictive settings for uploading
thanks
- April 8, 2019 at 6:54 am #56773WCFM ForumKeymaster
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
- April 8, 2019 at 7:40 am #56784HamidGuest
Thanks
I mean the file size (image file, Zip file or …)
Example: 50 MBI have a file sales store..
- April 8, 2019 at 8:05 am #56786WCFM ForumKeymaster
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
- AuthorPosts
Viewing 3 reply threads
- The topic ‘Add limited file size upload (for vendor)’ is closed to new replies.