<input type='hidden' name='MAX_FILE_SIZE' value='".$max_file_size."'>
<?php //Set allowed extensions and filesize $allowedextensions = 'jpg,JPG,jpeg,JPEG,doc,docx,pdf,PDF,txt,png,PNG,zip'; $maxfilesize = 12582912; //Size limit in bytes //Set error messages //Coded max file size is bigger than the stated size for flexibility $error_oversize = 'File size is limited to 10MB.'; $error_wrongtype = 'File type not supported.'; // Get file name and size. //'document' is the name of the input on the form $filename = basename( $_FILES['document']['name'] ); $filesize = filesize( $_FILES['document']['tmp_name'] ); // Get file's extension $ext = pathinfo($filename, PATHINFO_EXTENSION); //Fill an array with the allowed extensions $ext_array = explode(',', $allowedextensions); //Check the extension against the allowed set //&& check file is not over size if( (in_array($ext, $ext_array)) && ($filesize < $maxfilesize) ) { //Succeed return true; } else { if (!in_array($ext, $ext_array)) { $errormsg = $error_wrongtype; } if ($filesize > $maxfilesize) { $errormsg = $error_oversize; } //Fail and generate error message $validator->addError('document',$errormsg); return false; } ?>
<?php //Set allowed extensions and filesize $allowedextensions = 'jpg,jpeg,png,gif,tif,doc,docx,xls,xlsx,ods,ots,odg,odp,pdf,txt,rtf,zip'; //Size limit in Mega bytes $maxfilesize = (float)$param * 1048576; // byte to mb //Set error messages //Coded max file size is bigger than the stated size for flexibility $error_oversize = 'File size is limited! max. ' .$maxfilesize/1048576 . 'MB!'; $error_wrongtype = 'File type not supported! only: ' .$allowedextensions; // Get file name and size. //'document' is the name of the input on the form $filename = basename( $_FILES['document']['name'] ); $filesize = filesize( $_FILES['document']['tmp_name'] ); // if without document if ($filename == '') { return true; } // Get file's extension $ext = strtolower(pathinfo($filename, PATHINFO_EXTENSION)); //Fill an array with the allowed extensions $ext_array = explode(',', $allowedextensions); //Check the extension against the allowed set //&& check file is not over size if( (in_array($ext, $ext_array)) && ($filesize <= $maxfilesize) ) { //Succeed return true; } else { if (!in_array($ext, $ext_array)) { $errormsg = $error_wrongtype; } if ($filesize > $maxfilesize) { $errormsg = $error_oversize; } //Fail and generate error message $validator->addError($key,$errormsg); return false; }
[[!FormIt? .... &customValidators=`maxFileSize` &validate=`document:maxFileSize=`4.5`` .... ]]
<div> <label for="image-upload1" class="formlabels">Upload Image 1:</label> <input name="image-upload1" type="file" class="forminputs" id="image-upload1" value="[[!+fi.image-upload1]]"/><br/><span class="validationerror">[[!+fi.error.image-upload1]]</span> </div>
[[!FormIt? &hooks=`spam,email,redirect` &customValidators=`maxFileSize` &validate=`document:maxFileSize=`2`` &emailTpl=`f5.laheta-tiedosto-lahetys.tpl` &emailSubject=`Tiedosto sivuilta` &emailTo=`[[+addressTo]]` &redirectTo=`x` ]]
<label for="liite">Valitse tiedosto: <input id="liite" type="file" name="liite" value="[[+fi.liite]]" /> </label>
<input id="liite" type="file" name="document" value="[[+fi.liite]]" />
&validate=`document:maxFileSize=`2``
&validate=`document:maxFileSize=^2^`
<?php //Set allowed extensions and filesize $allowedextensions = 'jpg,jpeg,png,gif,tif,doc,docx,xls,xlsx,ods,ots,odg,odp,pdf,txt,rtf,zip'; //Size limit in Mega bytes $maxfilesize = (float)$param * 1048576; // byte to mb //Set error messages //Coded max file size is bigger than the stated size for flexibility $error_oversize = 'File size is limited! max. ' .$maxfilesize/1048576 . 'MB!'; $error_wrongtype = 'File type not supported! only: ' .$allowedextensions; // Get file name and size. $filename = basename( $_FILES[$key]['name'] ); $filesize = filesize( $_FILES[$key]['tmp_name'] ); // if without document if ($filename == '') { return true; } // Get file's extension $ext = strtolower(pathinfo($filename, PATHINFO_EXTENSION)); //Fill an array with the allowed extensions $ext_array = explode(',', $allowedextensions); //Check the extension against the allowed set //&& check file is not over size if( (in_array($ext, $ext_array)) && ($filesize <= $maxfilesize) ) { //Succeed return true; } else { if (!in_array($ext, $ext_array)) { $errormsg = $error_wrongtype; } if ($filesize > $maxfilesize) { $errormsg = $error_oversize; } //Fail and generate error message $validator->addError($key,$errormsg); return false; }
$filename = basename( $_FILES['document']['name'] ); $filesize = filesize( $_FILES['document']['tmp_name'] );
$filename = basename( $_FILES[$key]['name'] ); $filesize = filesize( $_FILES[$key]['tmp_name'] );
&customValidators=`maxFileSize` &validate=` cover:maxFileSize=^1.5^, document:maxFileSize=^1.5^