#636 TFileValidator, TImageValidator, TFileUpload and TActiveFileUpload tweaks - #1246
Merged
Merged
Conversation
…t and capture, TActiveFileUpload causes validation, and has validation group. unit and functional tests
belisoful
marked this pull request as ready for review
August 26, 2026 22:18
belisoful
marked this pull request as draft
August 26, 2026 22:18
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TFileValidator, TImageValidator, and file upload validation (closes #636)
Implements the client- and server-side file upload validation requested in #636, built on the Prado validator architecture. No new dependencies: server-side image checks use core
getimagesize(), MIME sniffing uses the bundledfileinfoextension with graceful degradation.New components
TFileValidator— validates the files of aTFileUpload: per-fileMaxFileSize/MinFileSize, combinedTotalMaxFileSize,MinFileCount/MaxFileCount,AllowedFileExtensions,AllowedFileTypes(image/*wildcards), and server-onlyCheckExtensionMimeType(sniffed content must correspond to the file name extension; map extendable viastatic::$extensionMimeTypes). Client side mirrors every check through the HTML5 File API before transfer.TImageValidator— extends TFileValidator withMin/MaxImageWidth,Min/MaxImageHeight, and a readable-image check.TFileUpload— newAcceptandCaptureproperties rendering the HTML5accept/captureattributes (advisory; inherited by TActiveFileUpload).TActiveFileUpload— newCausesValidation(default true) andValidationGroup; attached validators now gate the auto-upload client side and the page validates during the upload callback.Nuances
TRequiredFieldValidatorto require a file. Files with PHP upload error codes fail validation.AllowedFileExtensions/AllowedFileTypesare AND checks; when both are empty the restrictions derive from the target'sAcceptvalue with match-any-token (OR) semantics, mirroring the browser file picker.MaxFileSize=0(default) falls back to the target'sTFileUpload::MaxFileSize(1 MB default), so a size limit is always enforced — consistent with PHP's ownMAX_FILE_SIZEhandling.fileinfo, unknown extensions, or no local file passCheckExtensionMimeType; TImageValidator instead fails closed on any filegetimagesize()cannot read.change, undecoded files pass, the validator re-validates when decoding completes. A submit that outruns the decode posts back and the authoritative server check catches it.TBaseValidator::$_clientClassor thegetRawValidationValue()switches — the JS validators readcontrol.filesdirectly, soTRequiredFieldValidatorbehavior on file inputs is unchanged.{files}ErrorMessage token is replaced with the invalid file names (HTML-encoded server side,textContentclient side); client options keep the raw token for client-side substitution.CausesValidationdefaults to true, so uploads now validate. Previously, validators attached to a TActiveFileUpload were effectively inert (the auto-upload bypassed client validation andOnFileUploadwas raised without page validation). Now: the client gate skips the iframe upload while the selection is invalid, and$page->validate(ValidationGroup)runs inraiseCallbackEvent()beforeOnFileUpload— soTPage::getIsValid()can be false in existing handlers, and with the default emptyValidationGroupall default-group validators of the page validate during the upload callback. SetCausesValidation=falseto restore the old behavior, or assign a dedicatedValidationGroupto scope it. Related timing note: validation must happen during the upload callback — the selection never persists to a later postback (successful uploads clear the input and temp files are removed at callback end), and the status icons reflect transfer status only; validation feedback belongs to theOnFileUploadhandler.Tests & docs
70 PHPUnit tests, 40 vitest tests, and 11 Playwright tests (green on Chromium, Firefox, and WebKit; real PNG fixtures generated by
tests/playwright/validators/png.js). New error codefilevalidator_fileupload_required;classes.phpupdated;agents/knowledge files added/updated for all touched classes.