Image upload restrictions

I have the following

 if(isset($_FILES['avatar']) && $_FILES['avatar'] != NULL && $_avatar = $_FILES['avatar']['name'])
 {	
 	$ext = strtolower(pathinfo($_avatar, PATHINFO_EXTENSION));

	$filename = implode('.', array($user->username(), $ext));
	$upload = new Upload(kirby()->roots()->avatars() . DS . $filename, array(
		'input'     => 'avatar',
		'overwrite' => true
	));

 }

What I want to be able to do is restrict the uploads to certain criteria; file size, image size… how do I go about doing this?

See this page of the docs which will work for panel uploads, but looks your manually uploading. Im not sure its possible that way.

Whats the wider context of your code?

expanding on the membership plugin, allowing the upload of avatars on account edit, wanted to define criteria for such.

I am assuming this is a frontend upload form? The Upload class accepts a maxSize and an accept option, where you can set your limitations.

array(
  'input'     => 'avatar',
   'overwrite' => true,
   'maxSize' => 1024,
   'accept' => 'whatever'
));

where accept accepts a callback, example for the Panel source code:

      'accept' => function($upload) use($event) {
        if($upload->type() != 'image') {
          throw new Error(l('users.avatar.error.type'));
        }

Thanks @jimbobrjames for your help. Seems that @chrisgwynne is not very happy with our answers.

My apologies texnixe, I had not seen that there was a reply to this. My apologies, my than happy with the replies :slight_smile: