$this->primaryKey('id');
$this->addBehavior('Timestamp');
-
+ $this->addBehavior('Josegonzalez/Upload.Upload', [
+ 'photo' => [
+ 'fields' => [
+ 'dir' => 'logo_directory',
+ ],
+ 'filesystem' => [
+ 'root' => WWW_ROOT,
+ ],
+ 'path' => 'files{DS}{model}{DS}{field}{DS}{primaryKey}{DS}avatar',
+ ],
+ ]);
//----------------------------------------------------------------------
//-------------------------Logique BDD----------------------------------
//----------------------------------------------------------------------
$validator
->allowEmpty('photo');
+ $validator->provider('upload',new \Josegonzalez\Upload\Validation\DefaultValidation());
+
+ $validator->add('photo','file',[
+ 'rule' => ['mimeType', ['image/jpeg', 'image/png','image/gif','image/svg+xml']],
+ 'message' => "This format is not allowed. Please use jpeg, png, gif or svg."
+ ]);
+
+ //Check that the file is below the maximum height requirement (checked in pixels)
+ $validator->add('photo', 'fileBelowMaxHeight', [
+ 'rule' => ['isBelowMaxHeight', 350],
+ 'message' => 'This image should not be higher than 350px',
+ 'provider' => 'upload'
+ ]);
+
+ //Check that the file is below the maximum width requirement (checked in pixels)
+ $validator->add('photo', 'fileBelowMaxWidth', [
+ 'rule' => ['isBelowMaxWidth', 350],
+ 'message' => 'This image should not be wider than 350px',
+ 'provider' => 'upload'
+ ]);
+
+
+ // Check that the file is Above the minimum height requirement (checked in pixels)
+ $validator->add('photo', 'fileAboveMinHeight', [
+ 'rule' => ['isAboveMinHeight', 100],
+ 'message' => 'This image should at least be 100px high',
+ 'provider' => 'upload'
+ ]);
+
+ $validator->add('photo', 'fileBelowMaxSize', [
+ 'rule' => ['isBelowMaxSize', 1048576],
+ 'message' => 'This file is too large. Max size is 1 Mo.',
+ 'provider' => 'upload'
+ ]);
+
return $validator;
}