Class Phalcon\Validation\Validator\File

extends abstract class Phalcon\Validation\Validator

implements Phalcon\Validation\ValidatorInterface

Source on GitHub

Checks if a value has a correct file

  1. <?php
  2. use Phalcon\Validation\Validator\File as FileValidator;
  3. $validator->add(
  4. "file",
  5. new FileValidator(
  6. [
  7. "maxSize" => "2M",
  8. "messageSize" => ":field exceeds the max filesize (:max)",
  9. "allowedTypes" => [
  10. "image/jpeg",
  11. "image/png",
  12. ],
  13. "messageType" => "Allowed file types are :types",
  14. "maxResolution" => "800x600",
  15. "messageMaxResolution" => "Max resolution of :field is :max",
  16. ]
  17. )
  18. );
  19. $validator->add(
  20. [
  21. "file",
  22. "anotherFile",
  23. ],
  24. new FileValidator(
  25. [
  26. "maxSize" => [
  27. "file" => "2M",
  28. "anotherFile" => "4M",
  29. ],
  30. "messageSize" => [
  31. "file" => "file exceeds the max filesize 2M",
  32. "anotherFile" => "anotherFile exceeds the max filesize 4M",
  33. "allowedTypes" => [
  34. "file" => [
  35. "image/jpeg",
  36. "image/png",
  37. ],
  38. "anotherFile" => [
  39. "image/gif",
  40. "image/bmp",
  41. ],
  42. ],
  43. "messageType" => [
  44. "file" => "Allowed file types are image/jpeg and image/png",
  45. "anotherFile" => "Allowed file types are image/gif and image/bmp",
  46. ],
  47. "maxResolution" => [
  48. "file" => "800x600",
  49. "anotherFile" => "1024x768",
  50. ],
  51. "messageMaxResolution" => [
  52. "file" => "Max resolution of file is 800x600",
  53. "anotherFile" => "Max resolution of file is 1024x768",
  54. ],
  55. ]
  56. )
  57. );

Methods

public validate (Phalcon\Validation $validation, mixed $field)

Executes the validation

public isAllowEmpty (Phalcon\Validation $validation, mixed $field)

Check on empty

public __construct ([array $options]) inherited from Phalcon\Validation\Validator

Phalcon\Validation\Validator constructor

public isSetOption (mixed $key) inherited from Phalcon\Validation\Validator

Checks if an option has been defined

public hasOption (mixed $key) inherited from Phalcon\Validation\Validator

Checks if an option is defined

public getOption (mixed $key, [mixed $defaultValue]) inherited from Phalcon\Validation\Validator

Returns an option in the validator’s options Returns null if the option hasn’t set

public setOption (mixed $key, mixed $value) inherited from Phalcon\Validation\Validator

Sets an option in the validator