You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -2196,42 +2199,60 @@ Laravel provides a variety of validation rules that may be used to validate uplo
2196
2199
],
2197
2200
]);
2198
2201
2199
-
If your application accepts images uploaded by your users, you may use the `File` rule's `image` constructor method to indicate that the uploaded file should be an image. In addition, the `dimensions` rule may be used to limit the dimensions of the image:
Even though you only need to specify the extensions when invoking the `types` method, this method actually validates the MIME type of the file by reading the file's contents and guessing its MIME type. A full listing of MIME types and their corresponding extensions may be found at the following location:
2214
2206
2215
-
> [!NOTE]
2216
-
> More information regarding validating image dimensions may be found in the [dimension rule documentation](#rule-dimensions).
For convenience, minimum and maximum file sizes may be specified as a string with a suffix indicating the file size units. The `kb`, `mb`, `gb`, and `tb` suffixes are supported:
2222
2213
2223
2214
```php
2224
-
File::image()
2215
+
File::types(['mp3', 'wav'])
2225
2216
->min('1kb')
2226
-
->max('10mb')
2217
+
->max('10mb');
2227
2218
```
2228
2219
2229
-
<aname="validating-files-file-types"></a>
2230
-
#### File Types
2220
+
<aname="validating-files-image-files"></a>
2221
+
#### Validating Image Files
2231
2222
2232
-
Even though you only need to specify the extensions when invoking the `types` method, this method actually validates the MIME type of the file by reading the file's contents and guessing its MIME type. A full listing of MIME types and their corresponding extensions may be found at the following location:
2223
+
To validate that uploaded files are images, you can use the `File` rule's `image` constructor method. The `File::image()` rule ensures that the file under validation is an image (jpg, jpeg, png, bmp, gif, svg, or webp):
You may also validate the dimensions of an image. For example, to validate that an uploaded image is at least 1000 pixels wide and 500 pixels tall, you may use the `dimensions` rule:
2242
+
2243
+
```php
2244
+
use Illuminate\Validation\Rule;
2245
+
use Illuminate\Validation\Rules\File;
2246
+
2247
+
File::image()->dimensions(
2248
+
Rule::dimensions()
2249
+
->maxWidth(1000)
2250
+
->maxHeight(500)
2251
+
)
2252
+
```
2253
+
2254
+
> [!NOTE]
2255
+
> More information regarding validating image dimensions may be found in the [dimension rule documentation](#rule-dimensions).
0 commit comments