dframe/fileStorage

Add validation method isAllowedFileType()

Closed this issue · 0 comments

dusta commented

Transfer to the validation method

Before:

$filename = $_FILES['file']['name'];
$extension = strtolower(pathinfo($filename, PATHINFO_EXTENSION)); //Walidacja Rozszerzenia

$finfo = finfo_open(FILEINFO_MIME_TYPE);
$mime = finfo_file($finfo, $_FILES['file']['tmp_name']);  //Walidacja Mine
finfo_close($finfo);

if (!in_array($mime, ['application/pdf']) OR !in_array($extension, ['pdf'])) {
    return Response::renderJSON(['code' => 403, 'message' => 'Allowed only: \'pdf\''])
        ->status(403)
        ->display();
}

After:

$FileStorage->isAllowedFileType($filename, ['pdf'])