From 73b6c8225c9cdfb0d1b26e1f01a23bf43bc4026b Mon Sep 17 00:00:00 2001 From: Tartoob Date: Sat, 1 Apr 2017 17:40:30 +0400 Subject: [PATCH] Update uploadable.md Validation using Cakephp way --- docs/behaviors/uploadable.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/docs/behaviors/uploadable.md b/docs/behaviors/uploadable.md index d6c3dfe..cb73da9 100644 --- a/docs/behaviors/uploadable.md +++ b/docs/behaviors/uploadable.md @@ -180,6 +180,26 @@ In this case we would be able to change the filename to a field of the entity: This example will place all avatars of all users in the path `webroot/uploads/Users/`, and saves the file as `5.png` (example). +Validation +----- +To validate the file type before upload it you can use CakePHP validation. + + + $validator + ->add('avatar', 'file', [ + 'rule' => [ + 'mimeType', [ + 'image/jpeg', + 'image/png', + 'image/bmp', + 'image/x-windows-bmp', + 'image/gif' + ] + ], + 'message' => 'You are not allow to upload this file' + ]); + +This example will not allow uploading non-image files unless file content in mimeType list To Do -----