Restricting File Types

There are times when you may need to restrict the type of files uploaded from a client's machine. You can do so by using the ContentType property of SA-FileUp and a Select condition to save only files that are a certain type.

Once your file is uploaded, you would include the following line after you have created an instance of SA-FileUp:

<% 
	....
'--- Parses out the file name
'---
FName = Mid(upl.UserFilename, InstrRev(upl.UserFilename, "\") + 1)

 '--- This line parses out the Content type.
 '--- 
 FCONT = upl.ContentType 

'--- This would equal to
'--- "image/pjpeg"
'--- "image/gif"
'--- "text/plain", etc.

'--- You can then use the Select Case Condition to restrict the file type.
	Select Case LCase(FCONT) 
	Case "image/gif"
		upl.Save 
		Response.Write "<P>" & FName & " has been saved."
	
	Case "image/pjpeg" 
		upl.Save 
		Response.Write "<P>" & FName & " has been saved."
	
	Case Else
		upl.delete
		Response.Write  "<P>" & "You are restricted to only upload gif and Jpeg files.<BR>"
		Response.End 
	End Select

	....
%>

Let go though the code:


What did we learn?

Now you can restrict file types with ease.

That completes the Basics tutorial. You can also try the other tutorials:

 

Previous Page Next Page