ciao ragazzi.. mi spiegate xke questo script non funziona..
in pratica deve fare questo :
fare l'upload di una nuova immagine , cancellare quella che c'era in precedenza e aggiornare la tabella del database con il nome della nuova immagine.
ma non va !!!!
l'upload della foto funziona correttamente , ma non mi elimina la vecchia immagine
<%
'Sample file Field-SaveAs.asp
'Store extra upload info to a database
' and file contents to the disk
Server.ScriptTimeout = 5000
'Create upload form
'Using Huge-ASP file upload
'Dim Form: Set Form = Server.CreateObject("ScriptUtils.ASPForm")
'Using Pure-ASP file upload
Dim Form: Set Form = New ASPForm %><%
Server.ScriptTimeout = 1000
Form.SizeLimit = &HA00000'10MB
'was the Form successfully received?
Const fsCompletted = 0
If Form.State = fsCompletted Then 'Completted
arrname=split(Form("SourceFile").FileName,".")
if arrname(1)="gif" or arrname(1)="jpg" or arrname(1)="jpeg" then
'cancello la vecchia foto del profilo
dim percorso_file
percorso_file = rs_viewuser("fotoProfilo")
Dim ObjFSO
Set ObjFSO = CreateObject("Scripting.FileSystemObject")
If ObjFSO.FileExists( percorso_file ) = True Then
ObjFSO.DeleteFile( percorso_file )
End If
Set ObjFSO = Nothing
'''''''''''''''''''''''''''''''''''''''''''
'Create destination path+filename for the source file.
Dim DestinationPath, DestinationFileName
DestinationPath = Server.mapPath("public\profilo")
DestinationFileName = DestinationPath & "\" & Form("SourceFile").FileName
'DestinationFileName = DestinationPath & "\" & rs_viewuser("fotoProfilo")
'Open recordset to store uploaded data
Dim RS: Set RS = OpenUploadRS
'scrivo nella stringa il nuovo percorso
RS("fotoProfilo") = "public\profilo\" & Form("SourceFile").FileName
'RS("fotoProfilo") = "public\profilo\" & rs_viewuser("fotoProfilo")
'...
RS.Update
Response.write "
Source file names:"
Dim Field: For Each Field in Form.Files.Items
Response.write "
" & Field.FileName
Next
'{b}Save file to the destination
Form("SourceFile").SaveAs DestinationFileName
'{/b}
'response.write "<Font color=green>
SourceFile was saved as " & DestinationFileName )
'response.write "
See ListFiles table in " & Server.MapPath("mdb-database\utenti.mdb") & " database.</Font>"
Response.Redirect("visualizza_profilo.asp")
else
%>
<script>
alert("ERRORE : Impossibile aggiungere l'immagine. Controlla che l'estensione sia supportata");
location.replace("add-foto-profilo.asp");
</script>
<%
response.end
%>
<%
Response.Redirect("add-foto-profilo.asp")
End If
ElseIf Form.State > 10 then
Const fsSizeLimit = &HD
Select case Form.State
case fsSizeLimit: response.write "
<Font Color=red>Source form size (" & Form.TotalBytes & "B) exceeds form limit (" & Form.SizeLimit & "B)</Font>
"
case else response.write "
<Font Color=red>Some form error.</Font>
"
end Select
End If'Form.State = 0 then
Function OpenUploadRS()
Dim RS : Set RS = CreateObject("ADODB.Recordset")
'Open dynamic recordset, table Upload
Sql = "SELECT * FROM tbl_authors WHERE code='" & Request.QueryString("userCode") & "'"
RS.Open Sql,adoCon,2,3
'RS.Open "ListFiles", GetConnection, 2, 2
Set OpenUploadRS = RS
end Function
Function GetConnection()
dim Conn: Set Conn = CreateObject("ADODB.Connection")
Conn.Provider = "Microsoft.Jet.OLEDB.4.0"
Conn.open "Data Source=" & Server.MapPath("mdb-database\utenti.mdb")
set GetConnection = Conn
end function
%>