• Resolved ghourbanian

    (@ghourbanian)


    hey
    first of all thank you for your grate job!

    I need to make a limitation for max upload file size and also the format of file, in other word I need to upload just images that have less than 1 MB size.
    how should I set that?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hello @ghourbanian

    If you want to limit all images on your website, you could edit the php configuration and set something like this:
    upload_max_filesize = 1M

    Another script I’ve found out there is this one:

    function whero_limit_image_size($file) {
    
    	// Calculate the image size in KB
    	$image_size = $file['size']/1024;
    
    	// File size limit in KB
    	$limit = 200;
    
    	// Check if it's an image
    	$is_image = strpos($file['type'], 'image');
    
    	if ( ( $image_size > $limit ) && ($is_image !== false) )
            	$file['error'] = 'Your picture is too large. It has to be smaller than '. $limit .'KB';
    
    	return $file;
    
    }
    add_filter('wp_handle_upload_prefilter', 'whero_limit_image_size');

    thanks(*)

    But I believe this is not related to the plugin itself but to uploading files wordpress feature.

    Thread Starter ghourbanian

    (@ghourbanian)

    thank you for your answer but as I think you know this solution makes effet all the wordpress fonctionality and I don’t want this, I nedd to just make a limitation for upload fileld, not whole of my web site!

    Thread Starter ghourbanian

    (@ghourbanian)

    is there any chance to find solution?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to set limitation for Upload filed?’ is closed to new replies.