modifica persist asp upload

matmilan

Nuovo Utente
27 Nov 2012
17
0
1
ciao a tutti,

HTML:
<HTML>
<HEAD>
<TITLE>AspJpeg: da form a disco a db - in asp</TITLE>
</HEAD>
<BODY>

<!-- Image upload form. Notice the ENCTYPE attribute -->
<FORM ENCTYPE="multipart/form-data" METHOD="POST" ACTION="upload.asp">
<TABLE CELLPADDING="3" CELLSPACING="0" BORDER="0" BGCOLOR="#EEEEEE">
<TR><TD>Immagine:</TD><TD><INPUT TYPE=FILE NAME="MyFile"></TD></TR>
<TR><TD>Dimensione anteprima:</TD><TD>
<SELECT NAME="scale">
<OPTION VALUE="75">75%
<OPTION VALUE="50">50%
<OPTION VALUE="25">25%
<OPTION VALUE="10">10%
</SELECT></TD></TR>

<TR><TD>Descrizione:</TD><TD><TEXTAREA NAME="Description"></TEXTAREA></TD></TR>

<TR><TD COLSPAN="2"><INPUT TYPE="SUBMIT" VALUE="Upload"></TD></TR>
</TABLE>
</FORM>

</BODY>
</HTML>

Codice:
<HTML>
<HEAD>
<TITLE>AspJpeg </TITLE>
</HEAD>
<BODY>

<!-- this script is invoked by form.asp-->
<%
	' Create an instance of AspUpload object
	Set Upload = Server.CreateObject("Persits.Upload")

	' Compute path to save uploaded files to
	Path = Server.MapPath("/public/")


	' Capture uploaded file. Save returns the number of files uploaded
	Count = Upload.Save(Path)

	If Count = 0 Then
		Response.Write "Scegli immagine. <A HREF=""form_A_disco_A_db.asp"">riprova</A>."
		Response.End
	Else

		' Obtain File object representing uploaded file
		Set File = Upload.Files(1)

		' Is this a valid image file?
		If File.ImageType <> "UNKNOWN" Then

			' create instance of AspJpeg object
			Set jpeg = Server.CreateObject("Persits.Jpeg")
			
			' open uploaded file
			jpeg.Open( File.Path )

			' resize image accoring to "scale" option.
			' notice that we cannot use Request.Form, so we use Upload.Form instead.
			jpeg.Width = jpeg.OriginalWidth * Upload.Form("scale") / 100
			jpeg.Height = jpeg.OriginalHeight * Upload.Form("scale") / 100

			SavePath = Path & "\small_" & File.ExtractFileName

			' AspJpeg always generates JPEG thumbnails regardless of original format.
			' If the original file was not a JPEG, append .JPG extension.
			If UCase(Right(SavePath, 3)) <> "JPG" Then
				SavePath = SavePath & ".jpg"
			End If

			jpeg.Save SavePath

			' Using ADO, save both images in the database along with description.
			strConnect = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath("/mdb-database/aspjpeg.mdb")

			Set rs = Server.CreateObject("adodb.recordset")
			rs.Open "images", strConnect, 1, 3
			rs.AddNew
			
			' Use File.Binary to access binary data of uploaded file.
			rs("original_image").Value = File.ExtractFileName

			Set ThumbFile = Upload.OpenFile(SavePath)
			rs("thumbnail").Value = "\small_" & File.ExtractFileName

			rs("description") = Upload.Form("Description")

			rs.Update
			rs.Close
			Set rs = Nothing

			Response.Write "Fatto, sia il file originale che l'anteprima sono stati salvati nel database.<P>"
			Response.Write "una copia dei files è stata creata in cartella scelta dal webmaster "

		Else			
			Response.Write "Immagine non valida. <A HREF=""form_A_disco_A_db.asp"">riprova</A>."
			Response.End
		End If
	End If
%>
</BODY>
</HTML>

avrei la necessità di:
- caricare con un solo campo input più immagini
- nel db oltre nome del file, prima, mi metta il percorso del file (esempio: www.sito.it/public/cartella/img.jpg), questo sia per le anteprime che mi genera che per l'immagine grande
- le antepeime in una cartella e le immagini grandi in un' altra

é complicato?

ma se vorrei inserire altri campi input dove vanno messi? (quello sono capace a farlo)

Grazie mille in anticipo
 
Miracolosamente sono riuscito a far tutto l'unico problema è l'upload multiplo

questo è il codice modificato:
Codice:
<HTML>
<HEAD>
<TITLE>AspJpeg </TITLE>
</HEAD>
<BODY>

<!-- this script is invoked by form.asp-->
<%
	' Create an instance of AspUpload object
	Set Upload = Server.CreateObject("Persits.Upload")

	' Compute path to save uploaded files to
	Path = Server.MapPath("PERCORSO1")
	Path1 = Server.MapPath("PERCORSO2")


	' Capture uploaded file. Save returns the number of files uploaded
	Count = Upload.Save(Path)

	If Count = 0 Then
		Response.Write "Scegli immagine. <A HREF=""form_A_disco_A_db.asp"">riprova</A>."
		Response.End
	Else

		' Obtain File object representing uploaded file
		Set File = Upload.Files(1)

		' Is this a valid image file?
		If File.ImageType <> "UNKNOWN" Then

			' create instance of AspJpeg object
			Set jpeg = Server.CreateObject("Persits.Jpeg")
			
			' open uploaded file
			jpeg.Open( File.Path )

			' resize image accoring to "scale" option.
			' notice that we cannot use Request.Form, so we use Upload.Form instead.
			jpeg.Width = jpeg.OriginalWidth * Upload.Form("scale") / 100
			jpeg.Height = jpeg.OriginalHeight * Upload.Form("scale") / 100

			SavePath = Path1 & "\small-" & File.ExtractFileName

			' AspJpeg always generates JPEG thumbnails regardless of original format.
			' If the original file was not a JPEG, append .JPG extension.
			If UCase(Right(SavePath, 3)) <> "JPG" Then
				SavePath = SavePath & ".jpg"
			End If

			jpeg.Save SavePath

			' Using ADO, save both images in the database along with description.
			strConnect = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath("/mdb-database/foto.mdb")

			Set rs = Server.CreateObject("adodb.recordset")
			rs.Open "images", strConnect, 1, 3
			rs.AddNew
			
			' Use File.Binary to access binary data of uploaded file.
			rs("original_image").Value = "PERCORSO1" & File.ExtractFileName

			Set ThumbFile = Upload.OpenFile(SavePath)
			rs("thumbnail").Value = "PERCORSO2" & "/small-" & File.ExtractFileName

			rs("description") = Upload.Form("Description")

			rs.Update
			rs.Close
			Set rs = Nothing

			Response.Write "Fatto, sia il file originale che l'anteprima sono stati salvati nel database.<P>"
			Response.Write "una copia dei files è stata creata in cartella scelta dal webmaster "

		Else			
			Response.Write "Immagine non valida. <A HREF=""form_A_disco_A_db.asp"">riprova</A>."
			Response.End
		End If
	End If
%>
</BODY>
</HTML>
 
Ciao,

come già detto passano tutti i file, ho caricato anche un file .htaccess oltre ad altri file d'immagine.

Controlla e usa lo script di Paolo.

Valeria.
 
ma come potrei integrarlo? upload su db, upload in cartelle diverse... mi servono. Poi dopo in quello più di 4 file non posso caricare (giusto?)

Se le foto da caricare sono una ventina anche lo script di paolo diventerebbe una cosa lunga e impegnativa.
 
Ma come si comporta persits se ci sono più file con lo stesso nome?

A fare così anche se metto più foto nei campi input mi carica e ridimensiona solo la prima:

Modulo:
Codice:
<form id="primo" enctype="multipart/form-data" method="POST" action="caricamentocompletato.asp" style="color: white;">
<table cellspacing="0" cellpadding="3" border="0" bgcolor="#EEEEEE" style="margin-top:20px; margin-bottom:20px;">
<tbody>
<tr>
<td>Immagine 1:</td>
<td>
<input type="FILE" name="MyFile">
</td>
<td>Immagine 7: </td>
<td>
<input type="FILE" name="MyFile">
</td>
</tr>
<tr>
<td>Immagine 2:</td>
<td>
<input type="FILE" name="MyFile">
</td>
<td>Immagine 8: </td>
<td>
<input type="FILE" name="MyFile">
</td>
</tr>
<tr>
<td>Immagine 3:</td>
<td>
<input type="FILE" name="MyFile">
</td>
<td>Immagine 9: </td>
<td>
<input type="FILE" name="MyFile">
</td>
</tr>
<tr>
<td>Immagine 4:</td>
<td>
<input type="FILE" name="MyFile">
</td>
<td>Immagine 10: </td>
<td>
<input type="FILE" name="MyFile">
</td>
</tr>
<tr>
<td>Immagine 5: </td>
<td>
<input type="FILE" name="MyFile">
</td>
<td>Immagine 11: </td>
<td>
<input type="FILE" name="MyFile">
</td>
</tr>
<tr>
<td>Immagine 6: </td>
<td>
<input type="FILE" name="MyFile">
</td>
<td>Immagine 12: </td>
<td>
<input type="FILE" name="MyFile">
</td>
</tr>
<tr>
  <td style="text-align:center;" colspan="4">
  <input type="SUBMIT" value="Upload">
  </td>
</tr>
</tbody>
</table>
</form>

caricamentocopletato.asp
Codice:
<%
	' Create an instance of AspUpload object
	Set Upload = Server.CreateObject("Persits.Upload")

	' Compute path to save uploaded files to
	Path = Server.MapPath("/public/foto")
	Path1 = Server.MapPath("/public/thumbs")


	' Capture uploaded file. Save returns the number of files uploaded
	Count = Upload.Save(Path)

	If Count = 0 Then
		Response.redirect "errore.asp"
		Response.End
	Else

		' Obtain File object representing uploaded file
		Set File = Upload.Files(1)
		
		For Each File in Upload.Files

		' Is this a valid image file?
		If File.ImageType = "JPEG" or  File.ImageType = "PNG" or File.ImageType = "JPG" Then

			' create instance of AspJpeg object
			Set jpeg = Server.CreateObject("Persits.Jpeg")
			
			' open uploaded file
			jpeg.Open( File.Path )

			' resize image accoring to "scale" option.
			' notice that we cannot use Request.Form, so we use Upload.Form instead.
			jpeg.Width = 65
			jpeg.Height = 65

			SavePath = Path1 & "\small-" & File.ExtractFileName

			' AspJpeg always generates JPEG thumbnails regardless of original format.
			' If the original file was not a JPEG, append .JPG extension.
			If UCase(Right(SavePath, 3)) <> "JPG" Then
				SavePath = SavePath & ".jpg"
			End If

			jpeg.Save SavePath

			' Using ADO, save both images in the database along with description.
			strConnect = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath("/mdb-database/db.mdb")

			Set rs = Server.CreateObject("adodb.recordset")
			rs.Open "images", strConnect, 1, 3
			rs.AddNew
			
			' Use File.Binary to access binary data of uploaded file.
			rs("original_image").Value = "PERCORSO" & File.ExtractFileName

			Set ThumbFile = Upload.OpenFile(SavePath)
			rs("thumbnail").Value = "PERCORSO" & "/small-" & File.ExtractFileName

			rs("autore") = Upload.Form("autore")
			rs("events") = Upload.Form("events")

			rs.Update
			rs.Close
			Set rs = Nothing

            response.redirect "fatto.asp"

		Else			
			Response.redirect "errore.asp"
			Response.End
		End If
		next
	End If
%>
 

Discussioni simili