lundi 17 octobre 2022

Validating filename of uploaded file in Laravel 5.4

How can I validate the filename of uploaded image file?

The scenario is:

When a user upload an image the filename must its id, if not then it will throw an message that the filename must the user id.

This is my code:

    $validation = Validator::make($request->all(), [
            'documenttosubmit' => 'required|array',
            'datesubmitted' => 'required|array',
            'file' => 'array',
            'file.*' => 'mimetypes:' . implode(",", $allowedMimes) . '|max:' . (AppDocSubmitted::MAX_FILE_SIZE * 1024), 
        ], [
            'file.*.mimetypes' => 'File must be an image (jpg/jpeg/png) or a document (pdf).',
            'file.*.max' => 'File size must be less than the maximum size of ' . AppDocSubmitted::MAX_FILE_SIZE . 'MB',
        ]);


from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/0ZuW63a
via IFTTT

Aucun commentaire:

Enregistrer un commentaire