|
To check size and extension of uploaded files use the following
code in Add page: Before record added
and/or Edit page: Before record
updated events.
Note: Change
the values listed in red to
match your specific needs.
1. Check size and extension of
uploaded files stored on a hard drive
Check file size:
|
$mysize=$_FILES["value_FieldName_".postvalue("id")]["size"];
if($mysize>1000000) // if file size is
greater than 1Mb
{
$values["FieldName"]="";
$message = "<<< File is too big
>>>";
return false;
}
|
Check file extension:
|
$exttype =
CheckImageExtension($_FILES["value_FieldName_".postvalue("id")]["name"]);
if ($exttype <> ".JPG")
{
$message = "<<< Wrong file type selected
>>>";
return false;
}
|
2. Check size and extension of
uploaded files stored in a database
Check file size:
|
$mysize=$_FILES["value_FieldName_".postvalue("id")]["size"];
if($mysize>1000000) // if file size is greater than
1Mb
{
$values["FieldName"]="";
$message = "<<< File is too big
>>>";
return false;
}
|
Check file extension:
|
$exttype =
CheckImageExtension($_FILES["value_FieldName_".postvalue("id")]["name"]);
if ($exttype <> ".JPG")
{
$message = "<<< Wrong file type selected
>>>";
return false;
}
|
FieldName is the text
field that stores filename. Before using this sample code, make
sure that in Visual Editor you select this field for storing
filenames. For more information, see "View as" settings - File.
|