\Upload::register('validate', function (&$file) { switch($file['field']) { case "certificate": $file['mime_whitelist'] = array('text/plain'); // check $file['mime_type'] manually, how to generate an error message? break; case "icon": $file['ext_whitelist'] = array('img', 'jpg', 'jpeg', 'gif', 'png'); // check $file['ext_whitelist'] manually, how to generate an error message? break; } }); \Upload::process($some_config);
// custom validation for the different file types \Upload::register('validate', function (&$file) { switch($file['field']) { case "production-certificate": case "test-certificate": if ($file['mimetype'] !== 'text/plain') { $env = substr($file['field'], 0, strlen($file['field']) -strlen('-certificate')); $file['error'] = true; $file['errors'][] = array('error' => \Upload::UPLOAD_ERR_MIME_NOT_WHITELISTED, 'message' => "The $env certificate is not valid, please upload a plain/text certificate"); return false; } break; case "icon": if ( ! in_array($file['extension'], array('img', 'jpg', 'jpeg', 'gif', 'png')) ) { $file['error'] = true; $file['errors'][] = array('error' => \Upload::UPLOAD_ERR_EXT_NOT_WHITELISTED, 'message' => 'The icon is not a valid image, please try another icon'); return false; } break; } return true; }); \Upload::process(array('randomize' => true,)); \Debug::dump(\Upload::get_errors());
It looks like you're new here. If you want to get involved, click one of these buttons!