Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 14
  1. #1
    Utente di HTML.it L'avatar di Lino80
    Registrato dal
    Oct 2005
    Messaggi
    1,560

    upload e cancellazione foto da directory

    ciao, con questo script faccio l upload della foto e la carico in una directory:

    codice:
    <%
    ' inizio 
    
    dim w_ID, w_Cod_Old, w_codice, w_Prodotto, w_PDescrizione, w_GDescrizione, w_GFoto 
    dim w_CPrezzo, w_RPrezzo, w_PuntiSconto, w_VPrezzo
    dim w_Categorie
    dim ByteRicevuti, FileBinario, DatiRicevuti, FirmaFile, ArrPezzi, item, Inizio
    dim Intestazione, ContenutoFile, NomeUpload, NomeFile, Upload1, DimensioneFile1, EstensioneFile1, textStream, i, j
    dim FSO, NomeFile1, Upload2, DimensioneFile2, EstensioneFile2, NomeFile2, maxdimp, maxdimg, controllostampa
    
    'Questa variabile setta il percorso di dove effettuare l'upolad
    'la cartella non puo non esistere lo script non la crea ! ! !
    percorso = "/public/"
    maxdimp=500000    ' dimensione massima immagine piccola
    maxdimg=1100000   ' dimensione massima immagine grande
    
    ByteRicevuti = Request.TotalBytes
    
    if ByteRicevuti > 0 then
    	DatiRicevuti = Request.BinaryRead(ByteRicevuti)
      FileBinario = RSBinaryToString(DatiRicevuti)	
    	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)
    
    		' Recupero i campi se sono compilati
    		if instr(Intestazione,"ID") > 0 then
    			w_ID = ContenutoFile
    		end if
    		if instr(Intestazione,"Cod_Old") > 0 then
    			w_Cod_Old = ContenutoFile
    		end if
    		'if instr(Intestazione,"codice") > 0 then
    			'w_codice = ContenutoFile
    		'end if
    		if instr(Intestazione,"Prodotto") > 0 then
    			w_Prodotto = ContenutoFile
    		end if
    		if instr(Intestazione,"PDescrizione") > 0 then
    			w_PDescrizione = ContenutoFile
    		end if
    		if instr(Intestazione,"GDescrizione") > 0 then
    			w_GDescrizione = ContenutoFile
    		end if
    		'if instr(Intestazione,"PFoto") > 0 then
    			'w_PFoto = ContenutoFile
    		'end if
    		if instr(Intestazione,"GFoto") > 0 then
    			w_GFoto = ContenutoFile
    		end if
    		if instr(Intestazione,"CPrezzo") > 0 then
    			w_CPrezzo = ContenutoFile
    		end if
    		if instr(Intestazione,"RPrezzo") > 0 then
    			w_RPrezzo = ContenutoFile
    		end if
    		if instr(Intestazione,"PuntiSconto") > 0 then
    			w_PuntiSconto = ContenutoFile
    		end if
    		'if instr(Intestazione,"Iva") > 0 then
    			'w_Iva = ContenutoFile
    		'end if		
    		'if instr(Intestazione,"GiacenzaInfinita") > 0 then
    			'w_GiacenzaInfinita = ContenutoFile
    		'end if	
    		'if instr(Intestazione,"Giacenza") > 0 then
    			'w_Giacenza = ContenutoFile
    		'end if	
    		'if instr(Intestazione,"Offerta") > 0 then
    			'w_Offerta = ContenutoFile
    		'end if	
    		'if instr(Intestazione,"Spediziona") > 0 then
    			'w_Spedizione = ContenutoFile
    		'end if	
    		'if instr(Intestazione,"SpeseSpedizione") > 0 then
    			'w_SpeseSpedizione = ContenutoFile
    		'end if	
    		'if instr(Intestazione,"Tipologia") > 0 then
    			'w_Tipologia = ContenutoFile
    		'end if	
    		if instr(Intestazione,"Categorie") > 0 then
    			w_Categorie = ContenutoFile
    		end if	
    		if instr(Intestazione,"VPrezzo") > 0 then
    			w_VPrezzo = ContenutoFile
            end if
    
    		' Qui recupero il file da uploadare (se presente) e lo scrivo
    		' sul server
    		if instr(Intestazione,"UPlFotop") > 0 then
    		  i = instr(Intestazione,"filename=")
    			j = instr(i + 10,Intestazione,chr(34))
    			NomeUpload = mid(Intestazione,i + 10,j-i-10)
    			i = instrRev(NomeUpload,"\")
    			NomeFile=""       ' max			
    			if i<>0 then
        	    NomeFile = mid(NomeUpload,i + 1)
        	else
        			NomeFile = NomeUpload
        	end if
    '     if i<>0 then			
          if NomeFile<>"" then
    				Set FSO = CreateObject("Scripting.FileSystemObject")
    				Upload1 = True
    				DimensioneFile1 = len(ContenutoFile)
    				if len(w_PFoto)=0 then
    					 NomeFile1 = NomeFile
    					 w_PFoto = NomeFile					 
     				else
     					 NomeFile1 = w_PFoto	
     				end if	 			
    				if DimensioneFile1 > maxdimp then
    					 Errore = Errore & "Dimensione immagine piccola ("&DimensioneFile1*0.001 & " kb)  maggiore del limite consentito ("&maxdimp*0.001 & " kb)
    "
    				else
    						EstensioneFile1 = LCase(right(NomeFile,4))				
    						if EstensioneFile1 <>".jpg" and EstensioneFile1 <>".gif" then
    							 Errore = Errore & "Tipo di file non corretto : "&EstensioneFile1&"
    "
    						else		 			
    								Set textStream = FSO.CreateTextFile(server.mappath(percorso & NomeFile1), True, False)
        						textStream.Write ContenutoFile
        						textStream.Close
        						Set textStream = Nothing
    						end if
    				end if	
    	   		Set FSO = Nothing
        	end if
    		end if
    
    		if instr(Intestazione,"UPlFotog") > 0 then
    		  i = instr(Intestazione,"filename=")
    			j = instr(i + 10,Intestazione,chr(34))
    			NomeUpload = mid(Intestazione,i + 10,j-i-10)
    			i = instrRev(NomeUpload,"\")
    			NomeFile=""       ' max			
    			if i<>0 then
    				 NomeFile = mid(NomeUpload,i + 1)
        	else
    					NomeFile = NomeUpload
        	end if
    '     if i<>0 then			
          if NomeFile<>"" then	
    				Set FSO = CreateObject("Scripting.FileSystemObject")
    				Upload2 = True
    				DimensioneFile2 = len(ContenutoFile)
    				if len(w_GFoto)=0 then
    					 NomeFile2 = NomeFile
    					 w_GFoto = NomeFile					 
     				else
     					 NomeFile2 = w_GFoto	
     				end if	 			
    				if DimensioneFile2 > maxdimg then
    					 Errore = Errore & "Dimensione immagine grande ("&DimensioneFile2*0.001 & " kb)  maggiore del limite consentito ("&maxdimg*0.001 & " kb)
    "
    				else
    						EstensioneFile2 = LCase(right(NomeFile,4))				
    						if EstensioneFile2 <>".jpg" and EstensioneFile2 <>".gif" then
    							 Errore = Errore & "Tipo di file non corretto : "&EstensioneFile2&"
    "
    						else		 			
    								Set textStream = FSO.CreateTextFile(server.mappath(percorso & NomeFile2), True, False)
        						textStream.Write ContenutoFile
        						textStream.Close
        						Set textStream = Nothing
    						end if
    				end if		
    	   		Set FSO = Nothing
        	end if
    		end if
    
    	next
    End if
    ecc.. ecc..

    ho il problema nel cancellare la foto dalla directory stessa, quando devo cancellare un prodotto.. praticamente l'operazione inversa..

    come si fa?

    grazie

  2. #2
    codice:
    Sub Cancella_File(NomeFile)
    Dim Fso
    Set Fso = Server.CreateObject("Scripting.FileSystemObject")
    	If Fso.FileExists(Server.MapPath(NomeFile)) Then
    	 Fso.DeleteFile(Server.MapPath(NomeFile))
    	End If
    Set Fso = Nothing
    End Sub
    
    Call Cancella_File("nomefile")
    Byeeeez

  3. #3
    Utente di HTML.it L'avatar di Lino80
    Registrato dal
    Oct 2005
    Messaggi
    1,560
    grazie.. cmq da pulsante: /elimina.asp?id=215&tabella=prodotti

    in base all ID devo cancellare la foto relativa..

    codice:
    Sub Cancella_File(NomeFile)
    Dim Fso
    Set Fso = Server.CreateObject("Scripting.FileSystemObject")
    	If Fso.FileExists(Server.MapPath(NomeFile)) Then
    	 Fso.DeleteFile(Server.MapPath(NomeFile))
    	End If
    Set Fso = Nothing
    End Sub
    
    Call Cancella_File("nomefile")
    al posto di "nomefile" cosa ci metto?

  4. #4
    Al posto di NomeFile recuperi il nome del file da eliminare dal database sfruttando l'id che passi alla pagina elimina.asp

  5. #5
    Utente di HTML.it L'avatar di Lino80
    Registrato dal
    Oct 2005
    Messaggi
    1,560
    con che codice recupero il file in base all id?

  6. #6
    Immagino che te dovrai eliminare il record di un prodotto giusto? Da come hai inserito il comando elimina.asp credo le elimini utilizzando l'id esatto? Prima di eliminare il record devi recuperarti il nome del file da eliminare, elimini il file e successivamente elimini il record.

  7. #7
    Utente di HTML.it L'avatar di Lino80
    Registrato dal
    Oct 2005
    Messaggi
    1,560
    si esatto..ma non so che stringa con relativo id mettere qua:

    Call Cancella_File("nomefile")


  8. #8
    Ciao Lino80,

    devi semplicemente effettuare una query che ti pigli il campo dove memorizzi il path del file, in base all'Id del prodotto.

    Passerai questo valore a NomeFile.

    Poi, se tutto è andato a buon fine ti cancelli il record(Perchè non vogliamo record che si riferiscano a file inesistenti).

    La query:

    codice:
    SELECT CampoNomeFile FROM Prodotti WHERE ID=" & Request.QueryString("id")
    
    'Oppure visto il tuo codice
    
    SELECT CampoNomeFile FROM " & Trim(Request.QueryString("tabella")) & " WHERE ID=" & Request.QueryString("id")
    Byeeeez

  9. #9
    Utente di HTML.it L'avatar di Lino80
    Registrato dal
    Oct 2005
    Messaggi
    1,560
    mi serve solo eliminare la foto dalla cartella..

    codice:
    Sub Cancella_File(NomeFile)
    Dim Fso
    Set Fso = Server.CreateObject("Scripting.FileSystemObject")
    	If Fso.FileExists(Server.MapPath(NomeFile)) Then
    	 Fso.DeleteFile(Server.MapPath(NomeFile))
    	End If
    Set Fso = Nothing
    End Sub
    
    Call Cancella_File("nomefile")
    non so cosa devo scriverci qua dentro:

    Call Cancella_File("path ID ecc ecc...")

    capi? :P

  10. #10
    Utente di HTML.it L'avatar di Lino80
    Registrato dal
    Oct 2005
    Messaggi
    1,560
    ho provato così:

    codice:
    <%
    	Dim QSID, QSTabella, SQL, RS, oper
    		
    	QSID = Request.QueryString("ID")
    	QSTabella = Request.QueryString("Tabella")	
    	
    	if oper = "DEL" then
        Set FSO = CreateObject("Scripting.FileSystemObject")
        if fileExist(percorso & QSID & ".jpg") then
            FSO.DeleteFile(percorso & QSID & ".jpg")
        end if
    end if
    		
    	If (QSID <> "") And (QSTabella <> "") And (LCase(QSTabella) <> "prodotti") And (LCase(QSTabella) <> "categorie") And (LCase(QSTabella) <> "scategorie") then 
    		SQL = " DELETE FROM " & QSTabella & " WHERE ID = " & QSID
    		Set RS = Conn.Execute(SQL)
    	End If
    	
    	If (LCase(QSTabella) = "scategorie") Then 
    		SQL = " Select ID FROM Prodotti WHERE Cancellato = False AND SCategoria = " & QSID
    		Set RS = Conn.Execute(SQL)
    		
    		If Not RS.Eof Then
    			Response.write "Errore: Non si possono cancellare categorie NON VUOTE. Cancellare tutti i sotto prodotti e le sottocategorie."
    			Response.End
    		Else
    			SQL = " Select ID FROM Categorie WHERE SCategoria = " & QSID
    			Set RS = Conn.Execute(SQL)
    			If Not RS.Eof Then
    				Response.write "Errore: Non si possono cancellare categorie NON VUOTE. Cancellare tutti i sotto prodotti e le sottocategorie."
    				Response.End
    			End If
    		End If
    		
    		SQL = " DELETE FROM SCategorie WHERE ID = " & QSID
    		Set RS = Conn.Execute(SQL)
    	End If
    	
    	If (LCase(QSTabella) = "categorie") Then 
    		SQL = " Select ID FROM Prodotti WHERE Cancellato = False AND Categoria = " & QSID
    		Set RS = Conn.Execute(SQL)
    		
    		If Not RS.Eof Then
    			Response.write "Errore: Non si possono cancellare categorie NON VUOTE. Cancellare tutti i sotto prodotti."
    			Response.End
    		End If
    		
    		SQL = " DELETE FROM categorie WHERE ID = " & QSID
    		Set RS = Conn.Execute(SQL)
    	End If
    	
    	If (LCase(QSTabella) = "prodotti") Then 
    		SQL = " DELETE FROM Prodotti WHERE Prodotti.ID = " & QSID
    		Set RS = Conn.Execute(SQL)
    	End If
    	
    	Set RS = Nothing
    	Conn.Close
    	Set Conn = Nothing
    	
    	Response.Redirect "ok.asp"
    
    %>
    va tutto bene..mi elimina il prodotto ma non la foto..forse sbaglio qua?:

    if fileExist(percorso & QSID & ".jpg") then
    FSO.DeleteFile(percorso & QSID & ".jpg")

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.