|
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
disc
Check file size:
filesize=lenb(GetUploadedFileContents("file_FieldName"))
if filesize>1000000 then ' if file size is greater than 1Mb
message = "File is too big"
BeforeAdd=false ' or BeforeEdit=false
exit function
end if
|
Check file extension:
exttype = CheckImageExtension(values("FieldName"))
if lcase(exttype)=".jpg" or lcase(exttype)=".gif" then
message = "Wrong file type selected"
BeforeAdd=false ' or BeforeEdit=false
exit function
end if
|
2. Check size and extension of
uploaded files stored in a database
Check file size:
filesize=lenb(values("FieldName"))
if filesize>1000000 then ' if file size is greater than 1Mb
message = "File is too big"
BeforeAdd=false ' or BeforeEdit=false
exit function
end if
|
Check file extension:
exttype = CheckImageExtension(values("FieldName"))
if lcase(exttype)=".jpg" or lcase(exttype)=".gif" then
message = "Wrong file type selected"
BeforeAdd=false ' or BeforeEdit=false
exit function
end if
|
, where FieldName is
the text field that stores filename. Before using this sample code,
make sure that you set a text field (in our example FieldName) in Visual Editor as a field
that will store filename. More info here.
|