close ad
Databridge V2 with MySQLi support IS Now Available!
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Permissable file types and file sizes

Thread began 5/03/2011 3:02 pm by Paul | Last modified 5/05/2011 10:18 am by Jason Byrnes | 1545 views | 9 replies |

PaulBeta Tester

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.

Sign in to reply to this post

Jason ByrnesWebAssist

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

Sign in to reply to this post

PaulBeta Tester

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?

Attached Files
index.zip
Sign in to reply to this post

Jason ByrnesWebAssist

the obvious problem i see is code order from line 76 - 107

php:
<?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:
<?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");
  }
}
?>
Sign in to reply to this post

PaulBeta Tester

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.

Sign in to reply to this post

Jason ByrnesWebAssist

glad to hear it is working.

Sign in to reply to this post

PaulBeta Tester

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)

Sign in to reply to this post

Jason ByrnesWebAssist

Using validation show if behaviors, you can show a different error for each validation that fails.

Sign in to reply to this post

PaulBeta Tester

Thanks - will explore

Sign in to reply to this post

Jason ByrnesWebAssist

you're welcome.

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