By 14 Dicembre 2010 0 Comments

AspSmartUpload – Esempio 3: upload con restrizioni

Carica uno o più file al server con restrizioni alla proprietà dei file (estensione, dimensione, directory fisica, ecc.) Il modulo HTML permette all’utente di selezionare il file (s). Il file ASP utilizza aspSmartUpload per impostare le restrizioni e salvare i file sul disco del server.
Nota: Le restrizioni possono essere impostate anche a livello globale utilizzando il Registro di sistema. Prendono poi la priorità rispetto alle restrizioni fissate nei file ASP (gli ISP sono particolarmente affezionati a questa funzione!).

Esempio di pagina HTML che esegue il POST :
<HTML>
<BODY BGCOLOR="white">
<H1>aspSmartUpload : Sample 1</H1><HR>
<FORM METHOD="POST" ACTION="Sample1.asp" ...
...ENCTYPE="multipart/form-data">
<INPUT TYPE="FILE" NAME="FILE1" SIZE="50"><BR>
<INPUT TYPE="FILE" NAME="FILE2" SIZE="50"><BR>
<INPUT TYPE="FILE" NAME="FILE3" SIZE="50"><BR>
<INPUT TYPE="FILE" NAME="FILE4" SIZE="50"><BR>
<INPUT TYPE="SUBMIT" VALUE="Upload">
</FORM>
</BODY>
</HTML>

Esempio di pagina ASP che riceve il POST :


<HTML>
<BODY BGCOLOR="white">
<H1>aspSmartUpload : Sample 3</H1>
<HR>
<%
On Error Resume Next
' Variables
' *********
Dim mySmartUpload
Dim intCount
' Object creation
' ***************
Set mySmartUpload = Server.CreateObject("aspSmartUpload.SmartUpload")
' Only allow txt or htm files
' ***************************
mySmartUpload.AllowedFilesList = "htm,txt"
' DeniedFilesList can also be used :
' Allow all files except exe, bat and asp
' ***************************************
' mySmartUpload.DeniedFilesList = "exe,bat,asp"
' Deny physical path
' *******************
mySmartUpload.DenyPhysicalPath = True
' Only allow files smaller than 50000 bytes
' *****************************************
mySmartUpload.MaxFileSize = 50000
' Deny upload if the total fila size is greater than 200000 bytes
' *********************************
mySmartUpload.TotalMaxFileSize = 200000
' Upload
' ******
mySmartUpload.Upload
' Save the files with their original names in a
'virtual path of the web server
' ********************************
intCount = mySmartUpload.Save("/aspSmartUpload/Upload")
' sample with a physical path
' intCount = mySmartUpload.Save("c:temp")
' Trap errors
' ***********
If Err Then
Response.Write("<b>Wrong selection : </b>" & Err.description)
Else
' Display the number of files uploaded
' ************************************
Response.Write(intCount & " file(s) uploaded.")
End If
%>
</BODY>
</HTML>


About the Author:

shared on wplocker.com