Bug?
Hello, me again with server validation on upload file.
It seems that it only works if you name the uploadfield "image"
name: image
<?php
if (!function_exists("WADFP_getImageHeight")){
function WADFP_getImageHeight($fileField){
$WA_ImageContentTypes = array("image/gif" => true , "image/jpeg" => true, "image/pjpeg" => true, "image/x-png" => true, "image/png" => true);
$height = -1;
if(isset($fileField) && isset($fileField["tmp_name"]) && isset($fileField["type"]) && isset($WA_ImageContentTypes[$fileField["type"]]) ){
$dimensions = getimagesize($fileField["tmp_name"]);
$height = $dimensions[1];
}
return $height;
}
}
?>
<?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 require_once("WA_ValidationToolkit/WAVT_Scripts_PHP.php"); ?>
<?php require_once("WA_ValidationToolkit/WAVT_ValidatedForm_PHP.php"); ?>
<?php
if (isset($_POST["button"])) {
$WAFV_Redirect = "";
$_SESSION['WAVT_up2_474_Errors'] = "";
if ($WAFV_Redirect == "") {
$WAFV_Redirect = $_SERVER["PHP_SELF"];
}
$WAFV_Errors = "";
$WAFV_Errors .= WAValidateRQ(((isset($_FILES["image"]))?"image":"") . "",true,1);
$WAFV_Errors .= WAValidateFE(((isset($_FILES["image"]))?"image":"") . "",".gif, .jpg, .jpeg, .png",true,2);
$WAFV_Errors .= WAValidateNM(((isset($_FILES["image"]))?$_FILES["image"]["size"]:"") . "",0,500000,"",",.",true,3);
$WAFV_Errors .= WAValidateNM(WADFP_getImageWidth((isset($_FILES["image"]))?$_FILES["image"]:"") . "",50,"","",",.",true,4);
$WAFV_Errors .= WAValidateNM(WADFP_getImageHeight((isset($_FILES["image"]))?$_FILES["image"]:"") . "",50,"","",",.",true,5);
if ($WAFV_Errors != "") {
PostResult($WAFV_Redirect,$WAFV_Errors,"up2_474");
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Unbenanntes Dokument</title>
</head>
<body>
<form action="" method="post" enctype="multipart/form-data" name="form1" id="form1">
<p>
<label for="image">Foto</label>
<input type="file" name="image" id="image" />
</p>
<p>
<input type="submit" name="button" id="button" value="Senden" />
</p>
</form>
</body>
</html>
name: up
<?php require_once("WA_ValidationToolkit/WAVT_Scripts_PHP.php"); ?>
<?php require_once("WA_ValidationToolkit/WAVT_ValidatedForm_PHP.php"); ?>
<?php
if (isset($_POST["button"])) {
$WAFV_Redirect = "";
$_SESSION['WAVT_up_801_Errors'] = "";
if ($WAFV_Redirect == "") {
$WAFV_Redirect = $_SERVER["PHP_SELF"];
}
$WAFV_Errors = "";
$WAFV_Errors .= WAValidateRQ(((isset($_FILES["up"]))?"up":"") . "",true,1);
$WAFV_Errors .= WAValidateFE(((isset($_FILES["up"]))?"up":"") . "",".gif, .jpg, .jpeg, .png",true,2);
$WAFV_Errors .= WAValidateNM(((isset($_FILES["up"]))?$_FILES["up"]["size"]:"") . "",0,500000,"",",.",true,3);
if ($WAFV_Errors != "") {
PostResult($WAFV_Redirect,$WAFV_Errors,"up_801");
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Unbenanntes Dokument</title>
</head>
<body>
<form action="" method="post" enctype="multipart/form-data" name="form1" id="form1">
<p>
<label for="up">Foto</label>
<input type="file" name="up" id="up" />
</p>
<p>
<input type="submit" name="button" id="button" value="Senden" />
</p>
</form>
</body>
</html>
Cheers
Denis