This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
I am trying to put image(file) validations in my model file but it seems to be not working as I want.Here below is my scenario.
fields.yaml
fields:
slider_image:
label: 'Slider Image (jpg,png,gif) (1920 X 600)'
mode: image
fileTypes: 'jpeg,jpg,png,gif'
useCaption: true
thumbOptions:
mode: crop
extension: auto
span: auto
required: 1
type: fileupload
Model.php
public $rules = [
'slider_image' => 'required|mimes:jpeg,jpg,png,gif',
];
public $customMessages = [
'slider_image.required' => 'Please select slider image',
'slider_image.mimes' => 'Please select valid slider image',
];
As you can clearly see here I have a file upload option called as slider_image and in my .yaml file I have put validations to upload only jpeg,jpg,png,gif
But the issue is with my validation rules.
Even if I upload any other extension file (i.e. .zip) I m always having an error message saying
Please select slider image
but it should rather display below error as I have already invalid extension file.
Please select valid slider image
If I do not upload any image then it should display first error and if I upload an invalid image then it should display second error.
Can someone tell me what is wrong in my current scenario here ?
Additionally, I wanted to know if there is any validation rule available through which we can check height width of the image and set rule of minimum height width to upload and put validation message based on it in our model file.
Thanks
I'm afraid I can't help, but I can confirm that file upload validation is behaving very strange...
(and I hope someone can shed some light on it)
It's not working for me either. Not at all :(
in fields.yml:
img_teaser:
label: 'Image'
mode: image
useCaption: false
span: auto
required: 0
type: fileupload
in the model:
public $rules = [
'img_teaser' => ['image']
];
When I upload JPGs or PNGs and save, flash message tells me, that "img_teaser must be an image" ... But i uploaded an image.
If I put:
public $rules = [
'img_teaser' => [mimes:jpeg,jpg,png,gif']
];
...and upload PNGs or JPGs or JPEGs the flash message tells me upon save: "The img teaser must be a file of type: jpeg, jpg, png, gif." ... but it is :/
when I put ...
'img_teaser' => ['max:500']
.... I would expect to only be able to upload files up to 500kb in size but actually can upload images with 2 megabytes and more and successfully save without any message...
So is thre something broken with file upload validation? Or am I missing something important.?
Thank you for any hints.
Last updated
Ok, This is what i have done in my fields.yaml file https://paste.ee/r/TCREk and this is my Slider.php model file https://paste.ee/r/to2Tf but still i am having the same problem.
1-4 of 4