Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

File upload: Size validator or setMaxFileSize()

For Zend_Form_Element_File, is there any difference between adding a Size validator and using setMaxFileSize?

$file->addValidator('Size', false, 1000000);

$file->setMaxFileSize(1000000);
like image 986
jblue Avatar asked Apr 11 '26 21:04

jblue


1 Answers

setMaxFileSize(1000000) will limit the size on the client side, i.e. the special MAX_FILE_SIZE tag will be created in the html, e.g.:

 <input type="hidden" name="MAX_FILE_SIZE" value="1000000" />

However this is not so secure because it is easy to change your html. Anyway, if you don't specify setMaxFileSize, ZF will automatically create it with value that is equal to the value of upload_max_filesize in you php.ini.

AddValidator performs more secure validation as you cannot change the value of maximum file size in your html. Also you can specify custom error messages when you use validator.

like image 146
Marcin Avatar answered Apr 14 '26 11:04

Marcin