Blog Sections Open
Validating Uploaded File Size in eForm Before Accepting the File
How to stop oversized file uploads in eForm with a small custom validation callback.
File uploads become much safer when the form rejects oversized files before the rest of the workflow continues. In eForm, a lightweight way to do that is to add a custom validation callback and inspect $_FILES directly.
The original pattern looked like this:
[!validatefilesize!]
[!eForm? ... &eFormOnValidate=`validatefilesize`!]
With a file field such as:
<input type="file" name="testfile" eform=":file:0">
And a validator similar to:
function validatefilesize($fields,&$vMsg,&$rMsg){
if ($_FILES['testfile']['size'] > 1024) {
$vMsg[]='File is too large';
}
}
The real value here is not the exact threshold, but the pattern itself: use the standard eForm validation flow, keep the rule close to the form, and fail early before later hooks try to process an invalid upload.
In real projects you would normally compare against a more realistic limit, validate MIME type as well, and keep the error message editor-friendly. But this remains a solid foundation for safer upload workflows in Evolution CMS.
Querying Resources by TV Value with xPDO in Evolution CMS
How to join modTemplateVarResource and find resources by a specific TV value through an xPDO query.
Building Tag Links for `getResourcesTag` in Evolution CMS
A practical pattern for turning TV-based tags into links and using getResourcesTag to render filtered archive pages.