Permissable file types and file sizes
Does anyone have any suggestions as to how i might setup DFP to limit user file type uploads to .jpg and file size 50kb?
Thank you, Paul.
Does anyone have any suggestions as to how i might setup DFP to limit user file type uploads to .jpg and file size 50kb?
Thank you, Paul.
you need to use server validation from either Form toolkit or CSS Form builder for this.
for File type, use File Extension validation. For the Server varaible, expand the form collection and select the File Filed form element (the firsst plain one, not one that has a lightning bolt next to it.
for file size, select number validation, for the server variable, click the lightning bolt, expand the form collection and select the File Filed File Size variable.
Set the maximum to 500
Ok, applied that to my upload page.
Uploaded a file that breached my server conditions to test and my load page blanked out!
You wanna take a look at my file?
the obvious problem i see is code order from line 76 - 107
<?php
if (($_SERVER["REQUEST_METHOD"] == "POST") && (isset($_SERVER["HTTP_REFERER"]) && strpos($_SERVER["HTTP_REFERER"], $_SERVER["SERVER_NAME"].$_SERVER["PHP_SELF"]) > 0) && isset($_POST)) {
$WAFV_Redirect = "upload-error.php";
$_SESSION['WAVT_index_168_Errors'] = "";
if ($WAFV_Redirect == "") {
$WAFV_Redirect = $_SERVER["PHP_SELF"];
}
$WAFV_Errors = "";
$WAFV_Errors .= WAValidateFE(((isset($_FILES["imageField"]))?$_FILES["imageField"]["name"]:"") . "",".jpg, .jpeg, .png",true,1);
$WAFV_Errors .= WAValidateNM(((isset($_FILES["imageField"]))?$_FILES["imageField"]["size"]:"") . "",0,50,"",",.",true,2);
$WAFV_Errors .= WAValidateNM(WADFP_getImageWidth((isset($_FILES["imageField"]))?$_FILES["imageField"]:"") . "",0,480,0,",.",true,3);
$WAFV_Errors .= WAValidateNM(WADFP_getImageHeight((isset($_FILES["imageField"]))?$_FILES["imageField"]:"") . "",0,360,0,",.",true,4);
if ($WAFV_Errors != "") {
PostResult($WAFV_Redirect,$WAFV_Errors,"index_168");
}
}
?>
<?php
if (!function_exists("WADFP_getImageWidth")){
function WADFP_getImageWidth($fileField){
$WA_ImageContentTypes = array("image/gif" => true , "image/jpeg" => true, "image/pjpeg" => true, "image/x-png" => true, "image/png" => true);
$width = -1;
if(isset($fileField) && isset($fileField["tmp_name"]) && isset($fileField["type"]) && isset($WA_ImageContentTypes[$fileField["type"]]) ){
$dimensions = getimagesize($fileField["tmp_name"]);
$width = $dimensions[0];
}
return $width;
}
}
?>
change that to:
<?php
if (!function_exists("WADFP_getImageWidth")){
function WADFP_getImageWidth($fileField){
$WA_ImageContentTypes = array("image/gif" => true , "image/jpeg" => true, "image/pjpeg" => true, "image/x-png" => true, "image/png" => true);
$width = -1;
if(isset($fileField) && isset($fileField["tmp_name"]) && isset($fileField["type"]) && isset($WA_ImageContentTypes[$fileField["type"]]) ){
$dimensions = getimagesize($fileField["tmp_name"]);
$width = $dimensions[0];
}
return $width;
}
}
?>
<?php
if (($_SERVER["REQUEST_METHOD"] == "POST") && (isset($_SERVER["HTTP_REFERER"]) && strpos($_SERVER["HTTP_REFERER"], $_SERVER["SERVER_NAME"].$_SERVER["PHP_SELF"]) > 0) && isset($_POST)) {
$WAFV_Redirect = "upload-error.php";
$_SESSION['WAVT_index_168_Errors'] = "";
if ($WAFV_Redirect == "") {
$WAFV_Redirect = $_SERVER["PHP_SELF"];
}
$WAFV_Errors = "";
$WAFV_Errors .= WAValidateFE(((isset($_FILES["imageField"]))?$_FILES["imageField"]["name"]:"") . "",".jpg, .jpeg, .png",true,1);
$WAFV_Errors .= WAValidateNM(((isset($_FILES["imageField"]))?$_FILES["imageField"]["size"]:"") . "",0,50,"",",.",true,2);
$WAFV_Errors .= WAValidateNM(WADFP_getImageWidth((isset($_FILES["imageField"]))?$_FILES["imageField"]:"") . "",0,480,0,",.",true,3);
$WAFV_Errors .= WAValidateNM(WADFP_getImageHeight((isset($_FILES["imageField"]))?$_FILES["imageField"]:"") . "",0,360,0,",.",true,4);
if ($WAFV_Errors != "") {
PostResult($WAFV_Redirect,$WAFV_Errors,"index_168");
}
}
?>
Got it!
I see now, my image width, being one of the validations, needed to run first in order for the validation to validate!
All working perfectly now.
Thank you for your speedy response.
Paul.
glad to hear it is working.
Quick question whilst on the validation tool topic.
How might i place the failed file upload parameter(s) on my error page
(if at all possible)
Using validation show if behaviors, you can show a different error for each validation that fails.
Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.
These out-of-the-box solutions provide you proven, tested applications that can be up and running now. Build a store, a gallery, or a web-based email solution.