Issue Type: Improvement Created: 2008-09-26T23:24:15.000+0000 Last Updated: 2008-10-01T09:21:20.000+0000 Status: Resolved Fix version(s): - 1.6.2 (13/Oct/08)
Reporter: Loic Bistuer (loic.bistuer) Assignee: Thomas Weidner (thomas) Tags: - Zend_Validate_File
Related issues: Attachments:
In Zend_Validate_File_Size I reckon it'd be great if _throw was setting _min and _max to the respective values of the getMin() and getMax() methods. Since both methods call _toByteString it would result in friendlier error messages when they make use of the %min and %max placeholders.
I would also suggest breaking the loop in _toByteString when $size >= 1024 (instead of $size > 1024), 1MB is imo more user friendly than 1024kB.
Also in isValid() there is $this->_setValue($size) which sets %value to a file size. It is a bit confusing since the default error messages more or less treat %value as a file name. Even though it's overwritten in _throw when $files is set it might surprise some people that use this validator manually. (Zend_Validate_File_FileSize and Zend_Validate_File_ImageSize also do something similar).
Last suggestion, maybe a %size placeholder set to the actual size of the tested file could be useful to some people.
Posted by Thomas Weidner (thomas) on 2008-09-28T13:38:30.000+0000
Fixed with r11536
Posted by Loic Bistuer (loic.bistuer) on 2008-09-28T23:35:33.000+0000
Hi Thomas, thanks for implementing my suggestions; you left one out though and because you didn't comment on it I reopen the issue in case it wasn't intentional.
Here is the message currently output by the validator: "Maximum allowed size for file 'test.doc' is '1048576' but '4615933' detected."
I'd say the following message would be much more friendly to the average user: "Maximum allowed size for file 'test.doc' is '1MB' but '4.4MB' detected"
Replacing the numeric values for _min, _max and _size by their string counterparts could be achieved in _throw, systematically or conditionally depending on a Boolean value given as a parameter of the constructor.
Posted by Thomas Weidner (thomas) on 2008-09-29T00:12:45.000+0000
This was not implemented for clearification of value. When both values are nearly the same the difference would not be visible.
When you have the limit with 1048576 and the file with 1048577 the resulting message would be "Maximum allowed size for file 'test.doc' is '1MB' but '1MB' detected."
Not really what we want :-)
Posted by Loic Bistuer (loic.bistuer) on 2008-09-29T01:44:11.000+0000
I see your point, but I'm not sure the benefit of displaying the full numeric value outweighs the disadvantages.
First because for most non-technical people 1048576 is nothing more than a scary 7 figures number.
Also because a lot of programmers will use custom messages which won't necessarily display both values, in which case they won't have this issue and will probably enjoy being able to customize the format of their values. The Boolean parameter for the constructor could be a good way to implement this, leaving it to the programmers to decide what they want.
I can also think of two workarounds to the issue you mentioned when both values are displayed:
Posted by Thomas Weidner (thomas) on 2008-10-01T09:21:19.000+0000
Fixed with r11565
Have you found an issue?
See the Overview section for more details.