0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

画像ファイル(jpeg, png, gif, webp, svg など)だけを選択できるように制限

Posted at

①accept="image/*"

accept="image/*" は、HTMLの 要素で使用される属性で、ユーザーが画像ファイル(jpeg, png, gif, webp, svg など)だけを選択できるように制限するためのものです。

使い方

<input type="file" accept="image/*">

詳細

・accept="image/" を指定すると、ファイル選択ダイアログで画像ファイルのみが選択可能になります。
・image/
は、すべての画像フォーマット(image/png, image/jpeg, image/gif など)を許可するワイルドカードです。

②バリデーション:image

ファイルは画像(jpg、jpeg、png、bmp、gif、svg、webp)であるか確認できる。

/Applications/MAMP/htdocs/Laravel/EXP-alert/app/Http/Requests/ItemFormRequest.php
public function rules()
{
    return [
        'image_path' => ['image', 'max:2048']
    ];
}

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?