close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

File Size, Image Size

Thread began 8/29/2010 6:09 am by Cologne | Last modified 8/31/2010 12:19 pm by Jason Byrnes | 3234 views | 12 replies |

Cologne

File Size, Image Size

Hi,

maybe I asked that times before, but its hard to figure out how that works and how it should be inserted into the page.

Again, it starts with all those enteries in the bindings panel. UPLOAD-FILE and FORM[0] where you can find th informations for the upload file.


I want to limit the filesize to 1MB - and have an error message (filesize is to big)

I want to limit the min image size to 50px width - and an error message (your file needs to be bigger that 50px width)

I want it required to upload an image - error message (please choose an image file)

I want only images - Errormessage (only images are allowed)


does that only work with server validation? How does it work? Which validation type do I choose?

It would be nice to have a tutorial for that, so that I dont have to ask again and again. DFP was easier cause it checks the file size etc.

Thanks for hlep and patience

Denis

Sign in to reply to this post

Cologne

OK, I got now...

file size
image size
and requiring

but how do I check the extension?

If I use servervalidation file extension, server variable form[0] image extension

but that does not work. I want to have all checked with server validation :-)

Denis

Sign in to reply to this post

Jason ByrnesWebAssist

Use the File Extension server validation, For server variable, click the ligtning bolt and select the file Field Simple File Name bindings from the form binding collection.

for the valid file extension list, do not include the dots. for example to allow gif and jpg, the extension list will look like:
gif jpg jpeg

Sign in to reply to this post

Cologne

:-( this does not work...

<?php require_once("WA_ValidationToolkit/WAVT_Scripts_PHP.php"); ?>
<?php require_once("WA_ValidationToolkit/WAVT_ValidatedForm_PHP.php"); ?>
<?php require_once("webassist/file_manipulation/helperphp.php"); ?>
<?php
if (isset($_POST["button"])) {
$WAFV_Redirect = "";
$_SESSION['WAVT_upload_432_Errors'] = "";
if ($WAFV_Redirect == "") {
$WAFV_Redirect = $_SERVER["PHP_SELF"];
}
$WAFV_Errors = "";
$WAFV_Errors .= WAValidateRQ(((isset($_FILES["image"]))?$_FILES["image"]["name"]:"") . "",true,1);
$WAFV_Errors .= WAValidateFE(((isset($_FILES["image"]))? preg_replace('/.[^.]*$/', '', $_FILES["image"]["name"]) :"") . "","gif jpg jpeg png",true,2);

if ($WAFV_Errors != "") {
PostResult($WAFV_Redirect,$WAFV_Errors,"upload_432");
}
}
?>
<?php
// WA_UploadResult1 Params Start
$WA_UploadResult1_Params = array();
// WA_UploadResult1_1 Start
$WA_UploadResult1_Params["WA_UploadResult1_1"] = array(
'UploadFolder' => "_upload/",
'FileName' => "test_[FileName]",
'DefaultFileName' => "",
'ResizeType' => "2",
'ResizeWidth' => "300",
'ResizeHeight' => "0",
'ResizeFillColor' => "" );
// WA_UploadResult1_1 End
// WA_UploadResult1 Params End
?>
<?php
WA_DFP_SetupUploadStatusStruct("WA_UploadResult1");
if(isset($_POST["button"])){
WA_DFP_UploadFiles("WA_UploadResult1", "image", "2", "[NewFileName]_[Increment]", "true", $WA_UploadResult1_Params);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.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" id="form1">
<p>
<input type="file" name="image" id="image" />
</p>
<p>
<?php
if (ValidatedField('upload_432','upload_432')) {
if ((strpos((",".ValidatedField("upload_432","upload_432").","), "," . "1" . ",") !== false || "1" == "")) {
if (!(false)) {
?>
Bitte ein Bild auswählen!
<?php //WAFV_Conditional upload.php upload_432(1:)
}
}
}?>
</p>
<p>
<?php
if (ValidatedField('upload_432','upload_432')) {
if ((strpos((",".ValidatedField("upload_432","upload_432").","), "," . "2" . ",") !== false || "2" == "")) {
if (!((strpos((",".ValidatedField("upload_432","upload_432").","), "," . "1" . ",") !== false || "1" == ""))) {
?>
Bitte nur Bilder hochladen!
<?php //WAFV_Conditional upload.php upload_432(2:1)
}
}
}?>
</p>
<p>
<input type="submit" name="button" id="button" value="Senden" />
</p>
</form>
</body>
</html>
Sign in to reply to this post

Jason ByrnesWebAssist

change:

php:
$WAFV_Errors .= WAValidateFE(((isset($_FILES["image"]))? preg_replace('/.[^.]*$/', '', $_FILES["image"]["name"]) :"") . "","gif jpg jpeg png",true,2);



to;

php:
$WAFV_Errors .= WAValidateFE(((isset($_FILES["image"]))? preg_replace('/^[^\.]*/', '', $_FILES["image"]["name"]) :"") . "",".gif .jpg .jpeg .png",true,2);
Sign in to reply to this post

Cologne

Does not work :-(

how do I know to change that regex thing :-( But it still does not work. maybe its a bug?






<?php require_once("WA_ValidationToolkit/WAVT_Scripts_PHP.php"); ?>
<?php require_once("WA_ValidationToolkit/WAVT_ValidatedForm_PHP.php"); ?>
<?php require_once("webassist/file_manipulation/helperphp.php"); ?>
<?php
if (isset($_POST["button"])) {
$WAFV_Redirect = "";
$_SESSION['WAVT_upload_432_Errors'] = "";
if ($WAFV_Redirect == "") {
$WAFV_Redirect = $_SERVER["PHP_SELF"];
}
$WAFV_Errors = "";
$WAFV_Errors .= WAValidateRQ(((isset($_FILES["image"]))?$_FILES["image"]["name"]:"") . "",true,1);
$WAFV_Errors .= WAValidateFE(((isset($_FILES["image"]))? preg_replace('/^[^\.]*/', '', $_FILES["image"]["name"]) :"") . "",".gif .jpg .jpeg .png",true,2);
if ($WAFV_Errors != "") {
PostResult($WAFV_Redirect,$WAFV_Errors,"upload_432");
}
}
?>
<?php
// WA_UploadResult1 Params Start
$WA_UploadResult1_Params = array();
// WA_UploadResult1_1 Start
$WA_UploadResult1_Params["WA_UploadResult1_1"] = array(
'UploadFolder' => "_upload/",
'FileName' => "test_[FileName]",
'DefaultFileName' => "",
'ResizeType' => "2",
'ResizeWidth' => "300",
'ResizeHeight' => "0",
'ResizeFillColor' => "" );
// WA_UploadResult1_1 End
// WA_UploadResult1 Params End
?>
<?php
WA_DFP_SetupUploadStatusStruct("WA_UploadResult1");
if(isset($_POST["button"])){
WA_DFP_UploadFiles("WA_UploadResult1", "image", "2", "[NewFileName]_[Increment]", "true", $WA_UploadResult1_Params);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.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" id="form1">
<p>
<input type="file" name="image" id="image" />
</p>
<p>
<?php
if (ValidatedField('upload_432','upload_432')) {
if ((strpos((",".ValidatedField("upload_432","upload_432").","), "," . "1" . ",") !== false || "1" == "")) {
if (!(false)) {
?>
Bitte ein Bild auswählen!
<?php //WAFV_Conditional upload.php upload_432(1:)
}
}
}?>
</p>
<p>
<?php
if (ValidatedField('upload_432','upload_432')) {
if ((strpos((",".ValidatedField("upload_432","upload_432").","), "," . "2" . ",") !== false || "2" == "")) {
if (!((strpos((",".ValidatedField("upload_432","upload_432").","), "," . "1" . ",") !== false || "1" == ""))) {
?>
Bitte nur Bilder hochladen!
<?php //WAFV_Conditional upload.php upload_432(2:1)
}
}
}?>
</p>
<p>
<input type="submit" name="button" id="button" value="Senden" />
</p>
</form>
</body>
</html>
Sign in to reply to this post

Jason ByrnesWebAssist

My apologies, I was steering you wrong.

the server variable to use is the Client file name.

and the extension list should contain the dots and be comma separated:
.gif, .jpg, .jpeg, .png


php:
$WAFV_Errors .= WAValidateFE(((isset($_FILES["image"]))? preg_replace('/.[^.]*$/', '', $_FILES["image"]["name"]) :"") . "","gif jpg jpeg png",true,2);



should be changed to:

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





sorry for leading you astray.

Sign in to reply to this post

Cologne

ok, it seems to work :-) thank you.

but I was a little confused about ClientFileName, cause this is only to find "upload files". If I take the simple FielField it works.

So, always I want to check something in the upload I take the ImageAttributes in my FORM?

What are the UPLOAD FILES attributes for? There are also 2 diffrent attributes (see server files2.jpg).

Thanks for your help!
Denis

Sign in to reply to this post

Cologne

One last question :-)

How do I get the size to limit the file-size. for example 1MB, the number must be 1000000 or something.

Same, when I check width and/or height, what do I enter, if I want to check the limit of 50px?

Cheers
Denis

Sign in to reply to this post

Cologne

Everything seems to work, exept the Image-Width and Height check :-(

<?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 require_once("webassist/file_manipulation/helperphp.php"); ?>
<?php
if (isset($_POST["button"])) {
$WAFV_Redirect = "tupload.php";
$_SESSION['WAVT_tupload_935_Errors'] = "";
if ($WAFV_Redirect == "") {
$WAFV_Redirect = $_SERVER["PHP_SELF"];
}
$WAFV_Errors = "";
$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);
$WAFV_Errors .= WAValidateNM(((isset($_FILES["image"]))?$_FILES["image"]["size"]:"") . "",0,250000,"",",.",true,3);
$WAFV_Errors .= WAValidateNM(WADFP_getImageWidth((isset($_FILES["image"]))?$_FILES["image"]:"") . "",50,0,"",",.",true,4);
$WAFV_Errors .= WAValidateNM(WADFP_getImageHeight((isset($_FILES["image"]))?$_FILES["image"]:"") . "",50,0,"",",.",true,5);

if ($WAFV_Errors != "") {
PostResult($WAFV_Redirect,$WAFV_Errors,"tupload_935");
}
}
?>
<?php
// WA_UploadResult1 Params Start
$WA_UploadResult1_Params = array();
// WA_UploadResult1_1 Start
$WA_UploadResult1_Params["WA_UploadResult1_1"] = array(
'UploadFolder' => "_upload/",
'FileName' => "[FileName]",
'DefaultFileName' => "",
'ResizeType' => "0",
'ResizeWidth' => "0",
'ResizeHeight' => "0",
'ResizeFillColor' => "" );
// WA_UploadResult1_1 End
// WA_UploadResult1 Params End
?>
<?php
WA_DFP_SetupUploadStatusStruct("WA_UploadResult1");
if(isset($_POST["button"])){
WA_DFP_UploadFiles("WA_UploadResult1", "image", "2", "[NewFileName]_[Increment]", "false", $WA_UploadResult1_Params);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>test</title>
</head>

<body>
<form action="" method="post" enctype="multipart/form-data" id="formUplaod">
<p>Image:
<input type="file" name="image" id="image" />
</p>
<p>
<?php
if (ValidatedField('tupload_935','tupload_935')) {
if ((strpos((",".ValidatedField("tupload_935","tupload_935").","), "," . "1" . ",") !== false || "1" == "")) {
if (!(false)) {
?>
Need an image!
<?php //WAFV_Conditional tupload.php tupload_935(1:)
}
}
}?></p>
<p>
<?php
if (ValidatedField('tupload_935','tupload_935')) {
if ((strpos((",".ValidatedField("tupload_935","tupload_935").","), "," . "2" . ",") !== false || "2" == "")) {
if (!((strpos((",".ValidatedField("tupload_935","tupload_935").","), "," . "1" . ",") !== false || "1" == ""))) {
?>
Must be an image!
<?php //WAFV_Conditional tupload.php tupload_935(2:1)
}
}
}?></p>
<p>
<?php
if (ValidatedField('tupload_935','tupload_935')) {
if ((strpos((",".ValidatedField("tupload_935","tupload_935").","), "," . "3" . ",") !== false || "3" == "")) {
if (!((strpos((",".ValidatedField("tupload_935","tupload_935").","), "," . "1" . ",") !== false || "1" == "") || (strpos((",".ValidatedField("tupload_935","tupload_935").","), "," . "2" . ",") !== false || "2" == ""))) {
?>
File-Size to big!
<?php //WAFV_Conditional tupload.php tupload_935(3:1,2)
}
}
}?></p>
<p>
<?php
if (ValidatedField('tupload_935','tupload_935')) {
if ((strpos((",".ValidatedField("tupload_935","tupload_935").","), "," . "4" . ",") !== false || "4" == "")) {
if (!((strpos((",".ValidatedField("tupload_935","tupload_935").","), "," . "1" . ",") !== false || "1" == "") || (strpos((",".ValidatedField("tupload_935","tupload_935").","), "," . "2" . ",") !== false || "2" == "") || (strpos((",".ValidatedField("tupload_935","tupload_935").","), "," . "3" . ",") !== false || "3" == ""))) {
?>
Width must be over 50px!
<?php //WAFV_Conditional tupload.php tupload_935(4:1,2,3)
}
}
}?></p>
<p>
<?php
if (ValidatedField('tupload_935','tupload_935')) {
if ((strpos((",".ValidatedField("tupload_935","tupload_935").","), "," . "5" . ",") !== false || "5" == "")) {
if (!((strpos((",".ValidatedField("tupload_935","tupload_935").","), "," . "1" . ",") !== false || "1" == "") || (strpos((",".ValidatedField("tupload_935","tupload_935").","), "," . "2" . ",") !== false || "2" == "") || (strpos((",".ValidatedField("tupload_935","tupload_935").","), "," . "3" . ",") !== false || "3" == ""))) {
?>
Height must be over 50px!
<?php //WAFV_Conditional tupload.php tupload_935(5:1,2,3)
}
}
}?></p>
<p>
<input type="submit" name="button" id="button" value="upload!" />
</p>
</form>
</body>
</html>
Sign in to reply to this post
loading

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...