Codice PHP:
<%
'----------------------------- LIST FOTO -----------------------------'
sub listFoto()
if len(request("id")) <> 0 then
%>
<h1>FOTO</h1>
<div id="notice"><%= request("notice") %></div>
<fieldset>
<legend>Miniatura</legend>
<div id="thumb">
<% formThumb(request("id")) %>
</div>
</fieldset>
<fieldset>
<legend>Galleria fotografica</legend>
<p class="center">
<input type="button" value="Inserisci Nuova" onclick="window.location.href='<%= url %>?action=newFoto&id=<%= request("id") %>'" />
</p>
<%
sql = "SELECT ID, url FROM Foto WHERE risorsa = " & Cint(request("id"))
dbOpen(sql)
if not objRS.EOF then
%>
<ul id="foto">
<%
Do While NOT objRS.EOF
%>
[*]
[img]<%= images & objRS([/img]" alt="<%= objRS("url") %>" />
[url="<%= url %>?action=delFoto&url=<%= Server.URLEncode(objRS("]&res=<%= request("id") %>">Elimina[/url]
<%
objRS.MoveNext
Loop
%>
[/list]
<p class="center">
<input type="button" value="Inserisci Nuova" onclick="window.location.href='<%= url %>?action=newFoto&id=<%= request("id") %>'" />
</p>
<%
else
%><p class="center">Nessuna foto presente</p><%
end if
dbClose(true)
%>
</fieldset>
<%
end if
end sub
'----------------------------- FORM NUOVA FOTO -----------------------------'
sub newFoto()
%>
<div class="center">
<h1>Inserisci una foto</h1>
<form enctype="multipart/form-data" method="post" action="<%= url %>?action=uploadFoto&id=<%= request("id") %>">
Seleziona la foto da inserire
<input type="file" name="file" /></p>
<input type="submit" value="Inserisci" /></p>
<p class="little">L'operazione potrebbe richiedere alcuni istanti, a seconda delle dimensioni della foto</p>
</form>
</div>
<%
end sub
dim Upload1, NomeFile1, DimensioneFile1
'----------------------------- UPLOAD NEW FOTO -----------------------------'
sub uploadFoto()
dim risorsa
risorsa = request("id")
upload()
If Upload1 = true then
insertFoto risorsa, NomeFile1
response.redirect url & "?action=listFoto&id=" & risorsa & "¬ice=" & Server.URLEncode("[b]" & NomeFile1 & "[/b] (" & DimensioneFile1*0.001 & "kb) è stata inserita correttamente!")
End If
if err.number <> 0 then
response.redirect url & "?action=listFoto¬ice=" & Server.URLEncode("Si e' verificato il seguente errore: " & err.description)
end if
end sub
'----------------------------- UPLOAD FOTO -----------------------------'
sub upload()
dim percorso, ByteRicevuti, DatiRicevuti, i, FileBinario, FirmaFile, ArrPezzi, item, Inizio, Intestazione, ContenutoFile, j, num
percorso = images
ByteRicevuti = Request.TotalBytes
if ByteRicevuti > 0 then
DatiRicevuti = Request.BinaryRead(ByteRicevuti)
For i = 1 To lenB(DatiRicevuti)
FileBinario = FileBinario & chr(ascB(midB(DatiRicevuti,i,1)))
Next
FirmaFile = left(FileBinario,instr(FileBinario,"" & vbCrLf)-1)
ArrPezzi = split(FileBinario,FirmaFile)
for item = 1 to ubound(ArrPezzi)-1
Inizio = instr(ArrPezzi(item),"" & vbCrLf & "" & vbCrLf)
Intestazione = left(ArrPezzi(item),Inizio-1)
Inizio = Inizio + len("" & vbCrLf) + len("" & vbCrLf)
ContenutoFile = mid(ArrPezzi(item),Inizio,len(ArrPezzi(item))-Inizio-1)
dim NomeUpload, NomeFile, FSO, EstensioneFile1, textStream
if instr(Intestazione,"file") > 0 then
i = instr(Intestazione,"filename=")
j = instr(i + 10,Intestazione,chr(34))
NomeUpload = mid(Intestazione,i + 10,j-i-10)
i = instrRev(NomeUpload,"\")
if i<>0 then
NomeFile = mid(NomeUpload,i + 1)
else
NomeFile = NomeUpload
end if
if i<>0 then
Set FSO = CreateObject("Scripting.FileSystemObject")
Upload1 = True
DimensioneFile1 = len(ContenutoFile)
EstensioneFile1 = right(ContenutoFile,3)
NomeFile1 = NomeFile
num = 1
Do While FSO.FileExists(server.mappath(percorso & NomeFile1))
NomeFile1 = left(NomeFile1, len(NomeFile1)-4) & num & "." & right(NomeFile1,3)
num = num + 1
Loop
Set textStream = FSO.CreateTextFile(server.mappath(percorso & NomeFile1), True, False)
textStream.Write ContenutoFile
textStream.Close
Set textStream = Nothing
Set FSO = Nothing
end if
end if
Next
end if
end sub
'----------------------------- INSERISCI FOTO NEL DATABASE-----------------------------'
sub insertFoto(risorsa, url)
sql = "INSERT INTO Foto (url, risorsa) VALUES ('" & url & "', " & risorsa & ")"
dbOpen(sql)
dbClose(false)
end sub
'----------------------------- CONFERMA ELIMINAZIONE FOTO -----------------------------'
sub delFoto()
if len(request("url")) <> 0 then
%><p class="center">Vuoi davvero eliminare questa foto?
[url="<%= url %>?action=delFotoDo&url=<%= request("]&res=<%= request("res") %>&type=<%= request("type") %>">SI[/url][url="javascript:history.go(-1)"]NO[/url]</p><%
end if
end sub
'----------------------------- ELIMINA FOTO -----------------------------'
sub delFotoDo()
if len(request("url")) <> 0 then
if NOT eraseFoto(request("url")) then
response.redirect url & "?action=listFoto&id=" & request("res") & "¬ice=" & Server.URLEncode("Si e' verificato il seguente errore: " & err.description)
else
'foto normale
if len(request("type")) = 0 then
sql = "DELETE FROM Foto WHERE url = '" & request("url") & "'"
else
sql = "UPDATE Risorse SET [thumb] = 'null' WHERE thumb = '" & request("url") & "'"
end if
dbOpen(sql)
dbClose(false)
response.redirect url & "?action=listFoto&id=" & request("res") & "¬ice=" & Server.URLEncode("La foto è stata eliminata correttamente")
end if
end if
end sub
'----------------------------- FUNZIONE ELIMINA FOTO -----------------------------'
function eraseFoto(url)
dim objFSO
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
if objFSO.FileExists(server.mappath(images & url)) then
objFSO.DeleteFile server.mappath(images & url), False
end if
if err.number = 0 then
eraseFoto = true
else
eraseFoto = false
end if
end function
'----------------------------- FORM MINIATURA -----------------------------'
sub formThumb(id)
dim mini
sql = "SELECT thumb FROM Risorse WHERE ID = " & CInt(id)
dbOpen(sql)
if NOT objRS.EOF then
mini = LCase(objRS("thumb"))
end if
dbClose(true)
if mini = "null" then
%>
<form enctype="multipart/form-data" method="post" action="<%= url %>?action=addThumb&id=<%= request("id") %>">
Inserisci la foto di presentazione che comparirà nella home</p>
<input type="file" name="file" /></p>
<input type="submit" value="Inserisci" /></p>
</form>
<%
else
%>
[img]<%= images & mini %>[/img]" />
[url="<%= url %>?action=delFoto&type=thumb&url=<%= Server.URLEncode(mini) %>&res=<%= id %>"]Elimina[/url]
<%
end if
end sub
'----------------------------- UPLOAD MINIATURA -----------------------------'
sub addThumb()
dim risorsa
risorsa = request("id")
upload()
If Upload1 = true then
insertThumb NomeFile1, risorsa
response.redirect url & "?action=listFoto&id=" & risorsa & "¬ice=" & Server.URLEncode("[b]" & NomeFile1 & "[/b] (" & DimensioneFile1*0.001 & "kb) è stata inserita correttamente!")
End If
if err.number <> 0 then
response.redirect url & "?action=listFoto¬ice=" & Server.URLEncode("Si e' verificato il seguente errore: " & err.description)
end if
end sub
'----------------------------- INSERISCI MINIATURA -----------------------------'
sub insertThumb(url, id)
sql = "UPDATE Risorse SET [thumb] = '" & url & "' WHERE ID = " & CInt(id)
dbOpen(sql)
dbClose(false)
end sub
'----------------------------- INSERISCI MINIATURA -----------------------------'
sub delThumb()
end sub
%>
Grazie a tutti