File Upload Control - Validate type and size

Hi. Is it possible to limit the size and kind of file than users can upload with File Upload Control?

Thanks,

Pau

Subject: yes, but…

You can only limit the size after it has been uploaded, unless you create an activex or java applet to do the file size checking locally before uploading.

On the file type, you can do a simple extension test, but obviously a user can lie about the extension, here is how I do it:

This javascript goes in the onsubmit, the regulat expression is making sure one of the supported file types is present. The Upload Control has been named UpldControl.

UpldFile = UpldControl.value.toLowerCase(); //Uploaded File Name

ChkExtRx = “^.*(([^.][.]jpg)|([^.][.]jpeg)|([^.][.]jpe)|([^.][.]png)|([^.][.]bmp)|([^.][.]gif)|([^.][.]tif)|([^.][.]tiff))$” //Uploaded File Extension Regular expression

if(UpldFile !=“” && UpldFile.search(ChkExtRx)==-1) { //Check to see if the uploaded file extension is a supported type

alert('The picture you are uploading does not have a recognized extenstion \

\n\nYou may upload pictures with the extension type of: \

\nBMP, GIF, JPE, JPG, JPEG, PNG, TIF')

return false;

}

Subject: RE: yes, but…

How can I name the control???

Subject: Select the File Upload control

And set it in the HTML properties:

Subject: RE: Select the File Upload control

Thanks for your answers.

The kind of file is done with your explanation. So I’m centering now in the size issue.

Is it possible to do that writing a WebQuerySave agent or something like that??

Pau

Subject: RE: Select the File Upload control

I found this link searching this forum

Subject: RE: Select the File Upload control

Thanks again Carl.

It has been really useful, I can display now a message saying that the file uploaded is too big, but it seems that @SetField(“SaveOptions”;“0”); still allows to attach the file.

It’s an option to avoid saving sent mails, but isn’t useful for me, as I want to avoid saving an attachment in a form.

Pau

Subject: RE: Select the File Upload control

Yes, you can attach the file – you have to, since the size check is done on the server, so the file needs to be uploaded – but setting SaveOptions to “0” prevents the document, and therefore the attachment, from being saved.

Subject: File Upload Control - Validate type and size

If a third party tool is a solution, you can use Zipmail for WebMail (www.zipmail.com). Here you can limit the size, name, extension, … before being uploaded.HTH