php - 如何验证 Laravel Backpack 中图片的权重?
问题描述
我正在使用backpackforlaravel(“backpack/crud”:“3.5.*”),这很棒。我做了一个图像 CRUD 部分。我有一个使用以下代码的请求文件验证。
return [
'name' => 'required|min:5|max:255',
'code' => 'required|min:2|max:20',
'image' => 'required|mimes:jpeg,png,jpg,gif|max:2048',
];
在我的控制器中,我有这个代码
$this->crud->addField([ // image
'label' => "Bandera",
'name' => "image",
'type' => 'image',
'upload' => true,
'crop' => false, // set to true to allow cropping, false to disable
'aspect_ratio' => 1, // ommit or set to 0 to allow any aspect ratio
'mime_types' => ['image'],
'filesize' => 5,
// 'disk' => 's3_bucket', // in case you need to show images from a different disk
// 'prefix' => 'uploads/images/profile_pictures/' // in case your db value is only the file name (no path), you can use this to prepend your path to the image src (in HTML), before it's shown to the user;
]);
现在它显示图像必须是以下类型的文件:jpeg、png、jpg、gif。图片不得超过 2048 个字符。
这是验证图像重量作为字符串,我需要一个正常的重量和类型验证
解决方案
使用该验证器数组时,您正在正确验证图像。
- 验证
mimes:jpeg,png,jpg,gif
检查它是否是图像。 - 验证
max:2048
对文件大小设置了最大值。
推荐阅读
- groovy - 在地图上使用 find{ },其中评估整个地图而不是每个元素
- apache - .htaccess ErrorDocument 未按预期运行
- powershell - 使用 PowerShell 在文件中用环境变量替换字符串
- f# - 如何在 F# 中按升序对变量进行排序?
- javascript - 使用 React 和上下文传递状态,在对象数组上映射什么都不返回,但数组显然已被填充
- c++ - 为什么当我尝试搜索超出双链表中第一个数据条目的数据时,程序会崩溃?
- java - GSON - 如何解析两个同名但参数不同的 JSONArray?
- javascript - JavaScript中索引和数据的区别?
- javascript - 如何预加载样式表
- c++ - 在 C++ 中找到两个向量之间最相似的值