logo
Welcome Guest! To enable all features please Login. New Registrations are disabled.

Notification

Icon
Error

Options
Go to last post Go to first unread
Tijs  
#1 Posted : Wednesday, February 4, 2009 2:31:43 PM(UTC)
Tijs

Rank: Sienn Developer

Reputation:

Groups: Administration
Joined: 10/8/2008(UTC)
Posts: 25
Man
Location: Netherlands

Often when one wants to enable web users to upload files of some kind, you want some kind of restriction to prevent people from uploading content that is unwanted or simply to large. To make this restriction, you do the following in userescape datacheck:

Code:
  
  'Assign the upload control to a htminputfile variable
  Dim tbUpload as System.Web.UI.HtmlControls.HtmlInputFile
  pbw.assign_control(Myform,"FLBT4",tbUpload)

  'check if a file is actually uploaded   
  Dim uploaden as boolean = False
  Try
    if tbUpload.PostedFile.Filename.tostring.length > 0 Then
      uploaden = true
    end if
  Catch
    uploaden = false
  End try

  if uploaden then
    'check on size, in this example the file may not be bigger than 5mb
    if tbUpload.PostedFile.ContentLength > 5242880 Then
      Return "Image is too big, maximum size is 5MBs"
    end if

    'Get the file extension
    Dim fileExt As String = ""
    fileExt = System.IO.Path.GetExtension(tbUpload.PostedFile.FileName).tostring.toupper
    select case fileExt 
     'if it's an image (in this example) then no problem
     Case ".JPG",".BMP",".GIF",".PNG"
       Return ""
     'if it's anything else, show error
     Case Else
       Return "You may only upload images (jpg,gif,png,bmp)" 
    End select

  else 
    Return ""
  End if

Edited by user Wednesday, February 4, 2009 2:32:55 PM(UTC)  | Reason: Not specified

Wanna join the discussion?! Login to your Sienn Forum forum account. New Registrations are disabled.

Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.