codice:
<%@ Page Trace="False" Language="vb" aspcompat="true" debug="true" validateRequest="false"%>
<%@ Import Namespace=System.Drawing %>
<%@ Import Namespace=System.Drawing.Imaging %>
<%@ Import Namespace=System %>
<%@ Import Namespace=System.Collections %>
<%@ Import Namespace=System.Web %>
<%@ Import Namespace=System.Web.UI %>
<%@ Import Namespace=System.Web.UI.WebControls %>
<%'INIZIO SCRIPT UPLOAD RESIZE IMAGE%>
<SCRIPT LANGUAGE="VBScript" runat="server">
const Lx = 200 ' max width for miniaturenails
const Ly = 240 ' max height for miniaturenails
Const Lx1 = 800 ' max width for miniaturenails
Const Ly1 = 800 ' max height for miniaturenails
Dim upload_miniature_dir = "public/image/miniature/" ' directory to upload file
Dim upload_foto_dir = "public/image/foto/" ' directory to upload file
Dim upload_foto_x_web_dir = "public/image/foto/" ' directory to upload file
Dim upload_miniature = "_miniatura" ' filename to save miniaturenail as (suffix added by script)
Dim upload_original = ""' filename to save original as (suffix added by script)
Dim upload_foto_x_web = "__foto_x_web" ' filename to save miniaturenail as (suffix added by script)
Const upload_max_size = 10240 ' max size of the upload (KB) note: this doesn't override any server upload limits
Dim sFileName = ""
dim fileExt ' used to store the file extension (saves finding it mulitple times)
dim newWidth, newHeight as integer ' new width/height for the miniaturenail
Dim newWidth1, newHeight1 As Integer ' new width/height for the miniaturenail
dim l2' temp variable used when calculating new size
dim fileFld as HTTPPostedFile' used to grab the file upload from the form
Dim originalimg As System.Drawing.Image ' used to hold the original image
dim msg ' display results
dim upload_ok as boolean' did the upload work ?
</script>
<%
randomize() ' used to help the cache-busting on the preview images
upload_ok = false
if lcase(Request.ServerVariables("REQUEST_METHOD"))="post" then
fileFld = Request.Files(0) ' get the first file uploaded from the form (note:- you can use this to itterate through more than one image)
upload_original = fileFld.FileName
sFileName = Left(upload_original, Len(upload_original) - 4)
if fileFld.ContentLength > upload_max_size * 1024 then
msg = "Sorry, the image must be less than " & upload_max_size & "Kb"
else
try
originalImg = System.Drawing.Image.FromStream(fileFld.InputStream)
' work out the width/height for the miniaturenail. Preserve aspect ratio and honour max width/height
' Note: if the original is smaller than the miniaturenail size it will be scaled up
If (originalImg.Width/Lx) > (originalImg.Width/Ly) Then
L2 = originalImg.Width
newWidth = Lx
newHeight = originalImg.Height * (Lx / L2)
if newHeight > Ly then
newWidth = newWidth * (Ly / newHeight)
newHeight = Ly
end if
Else
L2 = originalImg.Height
newHeight = Ly
newWidth = originalImg.Width * (Ly / L2)
if newWidth > Lx then
newHeight = newHeight * (Lx / newWidth)
newWidth = Lx
end if
End If
Dim miniature As New Bitmap(newWidth, newHeight)
'Create a graphics object
Dim gr_dest As Graphics = Graphics.FromImage(miniature)
' just in case it's a transparent GIF force the bg to white
dim sb = new SolidBrush(System.Drawing.Color.White)
gr_dest.FillRectangle(sb, 0, 0, miniature.Width, miniature.Height)
'Re-draw the image to the specified height and width
gr_dest.DrawImage(originalImg, 0, 0, miniature.Width, miniature.Height)
'§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§
'INIZIO Codice foto x web
If (originalimg.Width / Lx1) > (originalimg.Width / Ly1) Then
l2 = originalimg.Width
newWidth1 = Lx1
newHeight1 = originalimg.Height * (Lx1 / l2)
If newHeight1 > Ly1 Then
newWidth1 = newWidth1 * (Ly1 / newHeight1)
newHeight1 = Ly1
End If
Else
l2 = originalimg.Height
newHeight1 = Ly1
newWidth1 = originalimg.Width * (Ly1 / l2)
If newWidth1 > Lx1 Then
newHeight1 = newHeight1 * (Lx1 / newWidth1)
newWidth1 = Lx1
End If
End If
Dim foto_x_web As New Bitmap(newWidth1, newHeight1)
'Create a graphics object
Dim gr_dest1 As Graphics = Graphics.FromImage(foto_x_web)
' just in case it's a transparent GIF force the bg to white
Dim sb1 = New SolidBrush(System.Drawing.Color.White)
gr_dest1.FillRectangle(sb1, 0, 0, foto_x_web.Width, foto_x_web.Height)
'Re-draw the image to the specified height and width
gr_dest1.DrawImage(originalimg, 0, 0, foto_x_web.Width, foto_x_web.Height)
'FINE Codice foto x web
'§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§
try
fileExt = System.IO.Path.GetExtension(fileFld.FileName).ToLower()
originalimg.Save(Server.MapPath(upload_foto_dir & sFileName & fileExt), originalimg.RawFormat)
miniature.Save(Server.MapPath(upload_miniature_dir & sFileName & upload_miniature & fileExt), originalimg.RawFormat)
foto_x_web.Save(Server.MapPath(upload_foto_x_web_dir & sFileName & upload_foto_x_web & fileExt), originalimg.RawFormat)
msg = "Uploaded " & fileFld.FileName & " to " & Server.MapPath(upload_miniature_dir & sFileName & fileExt)
upload_ok = true
catch
msg = "Sorry, there was a problem saving the image."
end try
' Housekeeping for the generated miniaturenail
if not miniature is nothing then
miniature.Dispose()
miniature = Nothing
foto_x_web.Dispose()
foto_x_web = Nothing
end if
catch
msg = "Sorry, that was not an image we could process."
end try
end if
' House Keeping !
if not originalImg is nothing then
originalImg.Dispose()
originalImg = nothing
end if
end if
'FINE SCRIPT UPLOAD RESIZE IMAGE %>
<%
Dim nome, id_tipo_super_categoria, tipo_super_categoria, codice_tipo_super_categoria, voce_in_elenco, voce_in_menu, id_lingua, codice_lingua, codice_super_categoria,link_esterno, blank, descrizione img_tbn_1, img_1, spunta, opzione, messaggio, errore
%>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title> INSERISCI SUPER CATEGORIA </title>
<link href="/CSS/pannello-html5-css3.css" rel="stylesheet"><%'Richiamo x HTML5%>
<%'Posiz.sotto il CSS se no da fastidio ai bottoni in IE%>
<!--[if IE]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js">
</script>
<![endif]-->
<script type="text/javascript" language="javascript" src="/pannello/js/ajax-validator-pannello.js"></script>
<script type="text/javascript">
// INIZIO: Attivare un campo di testo con una checkbox: se spunto la checkbox posso scrivere all'interno della textbox.
function CheckCheckBox(frm)
{
//if (!frm.CheckThis.checked)
//frm.CheckThis.focus()
if (!frm.PRIVACY.checked)
frm.PRIVACY.focus()
}
// FINE: Attivare un campo di testo con una checkbox.
</script>
</head>
<%'*********************************************************************************************'*%>
<%'Questo script controlla che vengano compilati i campi DOPO aver premuto sul tasto INSERISCI. '*
Dim inserisci 'Questo valore lo si trova nel pulsante INSERISCI nel: value="inserisci" '*
inserisci = request.form("inserisci") '*
'***********************************************************************************************'*%>
<%
if inserisci <>"" then
voce_in_elenco=request.form("VOCE_IN_ELENCO")' Si/No - checkbox
voce_in_menu=request.form("VOCE_IN_MENU")' Si/No - checkbox
id_lingua=request.form("ID_LINGUA")'Numerico che proviene select
codice_lingua=trim(replace(request.form("CODICE_LINGUA"), "'", "''"))'Testo che proviene select
nome=trim(replace(request.form("NOME"), "'", "''"))'Testo che proviene da textbox
codice_super_categoria=trim(replace(request.form("CODICE_SUPER_CATEGORIA"), "'", "''"))' Testo
id_tipo_super_categoria=request.form("ID_TIPO_SUPER_CATEGORIA")'Numerico che proviene select
tipo_super_categoria=trim(replace(request.form("TIPO_SUPER_CATEGORIA"), "'", "''"))'Testo che proviene select
codice_tipo_super_categoria=trim(replace(request.form("CODICE_TIPO_SUPER_CATEGORIA"), "'", "''"))'Testo che proviene select
link_esterno=trim(replace(request.form("LINK_ESTERNO"), "'", "''"))'Memo che proviene da textbox
blank=request.form("BLANK")' Si/No - checkbox
descrizione=replace(request.form("DESCRIZIONE"), "'", "''")' Memo
img_tbn_1=trim(replace(request.form("IMG_TBN_1"), "'", "''"))' Memo
img_1=trim(replace(request.form("IMG_1"), "'", "''"))' Memo
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
' Visualizzo il msg di "errore" dopo aver cliccato sul tasto INSERISCI.
''Dim messaggio, errore
errore = 0
messaggio = "<div class='msg_errore'>Obbligatorio!</div>"
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
end if
%>
<body>
'...continua!