onValidateUpload

The onValidateUpload handler is called when an item (file or image) is uploaded by a LiveWhale user. You can perform additional validation checks on the item and anything returned by the function will be displayed to the user as a validation error. See below for an example module.

<?php
     $_LW->REGISTERED_APPS['my_app']=[
       'title'=>'My App',
       'handlers'=>['onValidateUpload'],
    ];

    class LiveWhaleApplicationMyApp {

      public function onValidateUpload($data_type, $info) { // on validation of content being uploaded
        global $_LW;
        if ($data_type=='images') { // if saving an image

            if (!in_array(@$info['extension'], array('jpg','jpeg'))) { // require extension
                return 'Only JPG images are permitted.';
            };
          
            if ($sizes=getimagesize(@$info['tmp_name'])) { // if image sizes found

                if ($sizes[0]<900 || $sizes[1]<600) { // require minimum size
                    return 'Images must be minimum 900 pixels wide and 600 pixels tall.';
                } else if ($sizes[0]!=$sizes[1]*1.5) { // require 3:2 ratio
                    return 'Uploaded images must conform to a 3:2 ratio of width:height.';
                }
            
            };
        };
      }

   }
?>