UPLOAD con controllo esistenza file


Utente Attivo
18 Lug 2007
Buongiorno, ho un problema che non riesco proprio a capire, a risolvere, se potete darmi una mano x favore.
Ho trovato su wb il codice di upload free (Free ASP Upload)
molto bello, permette varie cose, ma non riesco a capire come mettere il controllo sul file da caricare, x verificare se gia esige.
vi posto il codice:
option explicit
Response.Expires = -1
Server.ScriptTimeout = 600
' All communication must be in UTF-8, including the response back from the request
Session.CodePage = 65001
Dim intid
<!-- #include file="upload.asp" -->


' ****************************************************
' http://www.freeaspupload.net
' ****************************************************

Dim uploadsDirVar
uploadsDirVar = "C:\Inetpub\wwwroot\pippo\public\foto"

' Note: this file uploadTester.asp is just an example to demonstrate
' the capabilities of the freeASPUpload.asp class. There are no plans
' to add any new features to uploadTester.asp itself. Feel free to add
' your own code. If you are building a content management system, you
' may also want to consider this script: http://www.webfilebrowser.com/

function OutputForm()
<form name="frmSend" method="POST" enctype="multipart/form-data" accept-charset="utf-8" action="inserisci_fotoauto.asp?id_auto=<%= intid %>" onSubmit="return onSubmitForm();">
<B>File names:</B><br>
File 1: <input name="attach1" type="file" size=35><br>
INSERISCI LA DESCRIZIONE: <input type="hidden" name="descrizione" value="<%= intid %>" class="post"><br>

<!-- #################
File 2: <input name="attach2" type="file" size=35><br>
File 3: <input name="attach3" type="file" size=35><br>
File 4: <input name="attach4" type="file" size=35><br>#################################################### -->
<!-- These input elements are obviously optional and just included here for demonstration purposes -->

<input style="margin-top:4" type="submit" value="Upload">
end function

function TestEnvironment()
Dim fso, fileName, testFile, streamTest
TestEnvironment = ""
Set fso = Server.CreateObject("Scripting.FileSystemObject")
if not fso.FolderExists(uploadsDirVar) then
TestEnvironment = "<B>La cartella " & uploadsDirVar & " non esiste</B><br>Contatta l'amministratore"
exit function
end if
fileName = uploadsDirVar & "\test.txt"
on error resume next
Set testFile = fso.CreateTextFile(fileName, true)
If Err.Number<>0 then
TestEnvironment = "<B>La cartella " & uploadsDirVar & " non ha i permessi di scritture.</B><br>Contatta l'amministratore."
exit function
end if
If Err.Number<>0 then
TestEnvironment = "<B>La cartella " & uploadsDirVar & " non ha i permessi per cancellare</B>,Contatta l'amministratore."
exit function
end if
Set streamTest = Server.CreateObject("ADODB.Stream")
If Err.Number<>0 then
TestEnvironment = "<B>Il ADODB object <I>Stream</I> non funziona sul tuo server.</B><br>Contatta l'amministratore."
exit function
end if
Set streamTest = Nothing
end function

function SaveFiles
Dim Upload, fileName, fileSize, ks, i, fileKey, primo

Set Upload = New FreeASPUpload


' If something fails inside the script, but the exception is handled
If Err.Number<>0 then Exit function

SaveFiles = ""
ks = Upload.UploadedFiles.keys
if (UBound(ks) <> -1) then
SaveFiles = response.Write("riepilogo" )'qui devi togliere se vuoi
for each fileKey in Upload.UploadedFiles.keys
SaveFiles = SaveFiles & Upload.UploadedFiles(fileKey).FileName & " (" & Upload.UploadedFiles(fileKey).Length & "B) "

SaveFiles = "Non hai selezionato un file corretto"
end if
'SaveFiles = SaveFiles & "<br>ciciciciciic = " & Upload.Form("enter_a_number") & "<br>"
'SaveFiles = SaveFiles & "Checkbox values = " & Upload.Form("checkbox_values") & "<br>"
'SaveFiles = SaveFiles & "List values = " & Upload.Form("list_values") & "<br>"
'SaveFiles = SaveFiles & "Text area = " & Upload.Form("t_area") & "<br>"
SaveFiles = SaveFiles & "Descrizione = " & Upload.Form("descrizione") & "<br>"

dim conn, sql, secondo

secondo = Upload.Form("descrizione")

Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & server.MapPath("..\mdb-database\dati.mdb")
sql = "INSERT into Foto (id_foto, url) VALUES('"&secondo&"', '"&primo&"')"

Set conn=nothing

end function
nel file upload esiste questo:
Function GetFileName(strSaveToPath, FileName)
'This function is used when saving a file to check there is not already a file with the same name so that you don't overwrite it.
'It adds numbers to the filename e.g. file.gif becomes file1.gif becomes file2.gif and so on.
'It keeps going until it returns a filename that does not exist.
'You could just create a filename from the ID field but that means writing the record - and it still might exist!
'N.B. Requires strSaveToPath variable to be available - and containing the path to save to
Dim Counter
Dim Flag
Dim strTempFileName
Dim FileExt
Dim NewFullPath
dim objFSO, p, strSave

Set objFSO = CreateObject("Scripting.FileSystemObject")
strSaveToPath = "/pippo/public/foto/" ' percorso dalla root
Counter = 0

p = instrrev(FileName, ".")
FileExt = mid(FileName, p+1)
strTempFileName = left(FileName, p-1)
NewFullPath = strSaveToPath & "\" & FileName
Flag = False

Do Until Flag = True
If objFSO.FileExists(NewFullPath) = False Then
Flag = True
GetFileName = Mid(NewFullPath, InstrRev(NewFullPath, "\") + 1)
Response.write "bastaaaaaaaaaaaaaaaaaaaaaaaaaaaaa."

Counter = Counter + 1
NewFullPath = strSaveToPath & "\" & strTempFileName & Counter & "." & FileExt
Response.write "bastaaaaaaaaaaaaaaaaaaaaaaaaaaaaa."

End If
End Function
dove dice che bisogna fare la funzione strSaveToPath , ma non capisco come farla e dove metterla.
mi potete aiutare?? grazie