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
Copy file name to clipboardExpand all lines: validation.md
+19-6
Original file line number
Diff line number
Diff line change
@@ -2106,6 +2106,22 @@ Laravel provides a variety of validation rules that may be used to validate uplo
2106
2106
],
2107
2107
]);
2108
2108
2109
+
2110
+
<aname="validating-files-file-sizes"></a>
2111
+
#### File Sizes
2112
+
2113
+
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.
2114
+
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:
2115
+
2116
+
```php
2117
+
File::types(['mp3', 'wav'])
2118
+
->min('1kb')
2119
+
->max('10mb');
2120
+
```
2121
+
2122
+
<aname="validating-files-image-files"></a>
2123
+
#### Validating Image Files
2124
+
2109
2125
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.
2110
2126
2111
2127
use Illuminate\Support\Facades\Validator;
@@ -2125,16 +2141,13 @@ The `File::image()` rule makes sure that the file under validation must be an im
2125
2141
> By default the File::image() rule does not allow SVG files due to possible XSS attacks.
2126
2142
> If you need to allow SVG files, you can pass `allowSvg: true` as argument, e.g. `File::image(allowSvg: true)` and handle potentially unsafe SVG files manually.
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.
2132
-
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:
2147
+
You may 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:
0 commit comments