[Vuejs]-Vue / Laravel: How to validate files uploaded from the frontend?

0๐Ÿ‘

You need to check files extension :

$extension = $file->extension();
$allowed_file_types = ['jpg','png','gif'];
if (in_array($extension, $allowed_file_types)){
//do upload
}else{
Continue;
}

for file sizes check this thread

0๐Ÿ‘

You can use laravel image validation

$this->validate ($input, [
    'files.*.image' => 'image|max:200',
]):

Note: max(size) is in Kilobytes

You can also use dimension rule

$this->validate ($input, [
    'files.*.image' => 'dimensions:min_width=100,min_height=200'
]):

Laravel Image Validation

Laravel Image Dimensions Validation

0๐Ÿ‘

You can set the following rule in your validation โ€“

 'file' => 'required|max:100|mimes:jpg,png,bmp' // 100kb, mimes must have image extensions

Leave a comment