codice:
<%
Dim connection,fs
Dim descrizione, file_up
'fs --> oggetto file system
Set script_name = Request.ServerVariables("SCRIPT_NAME")
Set method = Request.ServerVariables("REQUEST_METHOD")
Set connection = Server.CreateObject("ADODB.Connection")
connection.Open(cr_connection_STRING_admin)
if (UCase(method) = "POST") then
Set upload = new cUpload
upload.Overwrite = false 'non permetto che il file venga sovrascritto
upload.Upload()
descrizione = upload.Form("descrizione")
file_up = upload.Form("file")
if (file_up = "") then
head = "Errore: Specificare un file"
else
upload.SetPath("../docs")
upload.SaveAll 'Salva il file in locale
'Inserimento nel db
Response.Write("No errori durante il caricamento del file, inserisco nel db
")
descrizione = Replace(descrizione,"'","''")
file_up = Replace(file_up,"'","''")
query = "INSERT INTO docs (descrizione, file) VALUES ('"+descrizione+"','"+file_up+"')"
connection.Execute(query)
Set upload = Nothing
end if
end if
%>
poi un pò di html e
codice:
<%
query = "SELECT descrizione,file FROM docs"
Set rec = Server.CreateObject("ADODB.Recordset")
rec.Open query,connection,3,3
%>
<TABLE width="50%" border="1" cellspacing="0" cellpadding="0">
<TR bgcolor="FF9900" class="titoli">
<TD><DIV align="center">descrizione</DIV></TD>
<TD><DIV align="center">file</DIV></TD>
<TD><DIV align="center">strumenti</DIV></TD>
</TR>
<% Do While Not rec.EOF %>
<TR>
<TD><%=rec("descrizione")%></TD>
<TD><%=rec("file")%></TD>
<TD></TD>
</TR>
<%
rec.MoveNext
Loop
%>
</TABLE>
</DIV>
<hr size="1">
<FORM action="<%=script_name%>" method="post" enctype="multipart/form-data" name="form1">
<TABLE width="45%" border="1" cellspacing="0" cellpadding="0">
<TR bgcolor="FF9900" class="titoli">
<TD colspan="2">Carica nuovo documento</TD>
</TR>
<TR class="testi">
<TD width="39%">descrizione</TD>
<TD width="61%"> <INPUT name="descrizione" type="text" class="testi" id="descrizione" value="<%=descrizione%>">
</TD>
</TR>
<TR class="testi">
<TD>documento</TD>
<TD><INPUT name="file" type="file" class="testi"></TD>
</TR>
<TR class="testi">
<TD colspan="2"><INPUT type="submit" name="Submit" value="Invia"></TD>
</TR>
</TABLE>
</FORM>
</BODY>
</HTML>
<%
rec.close()
connection.close()
Set rec = nothing
Set connection = nothing
%>
ecco a voi