« All Handlers

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?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.';
}

};
};
}

}
?>