close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Bug?

Thread began 9/22/2010 3:59 am by Cologne | Last modified 9/27/2010 10:57 am by Jason Byrnes | 2225 views | 7 replies |

Cologne

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

Sign in to reply to this post

Jason ByrnesWebAssist

can you be a bit more specific on the problem you are having?

I have tested both code samples, and both will fail validation if the conditions you have added are not met.

Sign in to reply to this post

Cologne

hi jason, i was more iritated by the look. I was so sure that there was a difference between the two codes, but its no.
Everything is fine and works well.
Sorry for that posting, you can delete if you want :-)
Im sorry,
Denis

Sign in to reply to this post

Jason ByrnesWebAssist

"irritated by the look" does not constitute a bug.


there _is_ a difference between the two.

In the first one, you have the following validation:
a file is required
the extension must a gif, jpeg, jpg or png
the size must be less then 500000 bytes
the width must be less then 50
the height must be less than 50

the second one you are not validating the width or the height, but both work. no bug.


Please, when reporting a problem, include specific details on what exactly the problem is. If the "look of the code is irritating" you, include that info, also include what specifically irritates you about it.

Sign in to reply to this post

Cologne

hello jason,
i got a little blackout when i saw that. The code with image i saved to have it by the hand. When i reproduced it with up, i thought the word image is part of the extension :-) i did that 2-3 times and really thought IMAGE must be in the code? So I asked if this could be a bug.
:-) cheers,
denis

Sign in to reply to this post

Jason ByrnesWebAssist

Thank you for the clarification, but it was not clear what you where asking in the initial post.

The initial post was very vague and did not include the details that you where asking about the "$_FILES["up"]" versus "$_FILES["image"]" code.


The $_FILES collection is much like the $_FORM or $_GET collection, but for File fields in a multipart/form-data encoded form.

There is a $_FILE variable for each File field you add to the form, in the same way that each text element in the form will have a $_POST variable.

Sign in to reply to this post

Cologne

Hi Jason,

now I know what was wrong :-)

I looked again on my saved upload file.

$WAFV_Errors .= WAValidateRQ(((isset($_FILES["image"]))?$_FILES["image"]["name"]:"") . "",true,1);
$WAFV_Errors .= WAValidateFE(((isset($_FILES["image"]))?$_FILES["image"]["name"]:"") . "",".gif, .jpg, .jpeg, .png",true,2);



The RQ and File-extension looks diffrent: (((isset($_FILES["image"]))?$_FILES["image"]["name"]:"") <--- this is my saved file. There is 2 times $_FILE

When I now create a server validation there is only 1 $_FILE.

$WAFV_Errors .= WAValidateRQ(((isset($_FILES["image"]))?"image":"") . "",true,1);
$WAFV_Errors .= WAValidateFE(((isset($_FILES["image"]))?"image":"") . "",".gif, .jpg, .jpeg, .png",true,2);



Was the code changed?

Denis

Sign in to reply to this post

Jason ByrnesWebAssist

that code will be created if you select the Field Name binding instead of the Simple File Name binding.

Sign in to reply to this post

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

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.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...