5 use Psr\Http\Message\UploadedFileInterface;
35 public function getValue( $name, array $settings, array $options ) {
36 $ret = $this->callbacks->getUploadedFile( $name, $options );
38 if ( $ret && $ret->getError() === UPLOAD_ERR_NO_FILE &&
39 !$this->callbacks->hasParam( $name, $options )
44 } elseif ( !$ret && $this->callbacks->hasParam( $name, $options ) ) {
69 return ini_get(
'upload_max_filesize' );
72 public function validate( $name, $value, array $settings, array $options ) {
75 UPLOAD_ERR_FORM_SIZE =>
'formsize',
76 UPLOAD_ERR_PARTIAL =>
'partial',
77 UPLOAD_ERR_NO_FILE =>
'nofile',
78 UPLOAD_ERR_NO_TMP_DIR =>
'notmpdir',
79 UPLOAD_ERR_CANT_WRITE =>
'cantwrite',
80 UPLOAD_ERR_EXTENSION =>
'phpext',
83 if ( !$value instanceof UploadedFileInterface ) {
88 $err = $value->getError();
89 if ( $err === UPLOAD_ERR_OK ) {
91 } elseif ( $err === UPLOAD_ERR_INI_SIZE ) {
98 $last = strtolower( substr( $size, -1 ) );
99 $size = intval( $size, 10 ) * ( $prefixes[
$last] ?? 1 );
103 } elseif ( isset( $codemap[$err] ) ) {
104 throw new ValidationException( $name, $value, $settings,
'badupload-' . $codemap[$err], [] );
112 public function stringifyValue( $name, $value, array $settings, array $options ) {