Old school is faithful. However, if you want to get the exact file size after downloading it, you can use the following:
$fileSize = $file->getClientSize();
Another solution would be to change the maximum upload file size in php.ini. The current file size limit will be displayed below.
echo $file->getMaxFilesize();
To get errors in the form, you must check the form and print any errors if the validation fails.
use Symfony\Component\HttpFoundation\Response;
$form = $this->createForm(new FileType(), $file);
$form->handleRequest($request);
if ($form->isValid()) {
$data = "stored successfully";
$statusCode = 200;
} else {
$data = $form->getErrors();
$statusCode = 500;
}
return new Response($data, $statusCode);
source
share