Damaged Organic
Damaged Organic

Reputation: 8467

Symfony file upload and UploadedFile::getClientSize()

I'm building file upload without Doctrine and such no validation via annotations or YAML available to me. Symfony presents uploaded file as Symfony\Component\HttpFoundation\File\UploadedFile object, which has getClientSize() method, description:

Returns the file size.

It is extracted from the request from which the file has been uploaded. Then is should not be considered as a safe value.

Then what should be considered safe? What then Symfony uses to validate Doctrine document entity via annotations or YAML?

Upvotes: 2

Views: 4036

Answers (1)

Igor Pantović
Igor Pantović

Reputation: 9246

You can use $file->getSize(). Symfony UploadedFile extends File which in turn extends SplFileInfo, which itself has ::getSize method.

As for Symfony Validation component, it uses PHP filesize function directly: FileValidator line 142

Upvotes: 5

Related Questions