Originariamente inviato da gadavitor
Funge.
Ciao,
Vito
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Test</title>
<script language="JavaScript">
<!--
function checkFileUpload(form,extensions,requireUpload,size Limit,minWidth,minHeight,maxWidth,maxHeight,saveWi dth,saveHeight) { //v2.08
document.MM_returnValue = true;
for (var i = 0; i<form.elements.length; i++) {
field = form.elements[i];
if (field.type.toUpperCase() != 'FILE') continue;
checkOneFileUpload(field,extensions,requireUpload, sizeLimit,minWidth,minHeight,maxWidth,maxHeight,sa veWidth,saveHeight);
} }
function checkOneFileUpload(field,extensions,requireUpload, sizeLimit,minWidth,minHeight,maxWidth,maxHeight,sa veWidth,saveHeight) { //v2.08
document.MM_returnValue = true;
if (extensions != '') var re = new RegExp("\.(" + extensions.replace(/,/gi,"|").replace(/s/gi,"") + ")$","i");
if (field.value == '') {
if (requireUpload) {alert('File is required!');document.MM_returnValue = false;field.focus();return;}
} else {
if(extensions != '' && !re.test(field.value)) {
alert('This file type is not allowed for uploading.\nOnly the following file extensions are allowed: ' + extensions + '.\nPlease select another file and try again.');
document.MM_returnValue = false;field.focus();return;
}
document.PU_uploadForm = field.form;
re = new RegExp(".(gif|jpg|png|bmp|jpeg)$","i");
if(re.test(field.value) && (sizeLimit != '' || minWidth != '' || minHeight != '' || maxWidth != '' || maxHeight != '' || saveWidth != '' || saveHeight != '')) {
checkImageDimensions(field,sizeLimit,minWidth,minH eight,maxWidth,maxHeight,saveWidth,saveHeight);
} }
}
function showImageDimensions(fieldImg) { //v2.08
var isNS6 = (!document.all && document.getElementById ? true : false);
var img = (fieldImg && !isNS6 ? fieldImg : this);
if ((img.minWidth != '' && img.minWidth > img.width) || (img.minHeight != '' && img.minHeight > img.height)) {
alert('Uploaded Image is too small!\nShould be at least ' + img.minWidth + ' x ' + img.minHeight); return;}
if ((img.maxWidth != '' && img.width > img.maxWidth) || (img.maxHeight != '' && img.height > img.maxHeight)) {
alert('Uploaded Image is too big!\nShould be max ' + img.maxWidth + ' x ' + img.maxHeight); return;}
if (img.sizeLimit != '' && img.fileSize > img.sizeLimit) {
alert('Uploaded Image File Size is too big!\nShould be max ' + (img.sizeLimit/1024) + ' KBytes'); return;}
if (img.saveWidth != '') document.PU_uploadForm[img.saveWidth].value = img.width;
if (img.saveHeight != '') document.PU_uploadForm[img.saveHeight].value = img.height;
document.MM_returnValue = true;
}
function checkImageDimensions(field,sizeL,minW,minH,maxW,ma xH,saveW,saveH) { //v2.08
if (!document.layers) {
var isNS6 = (!document.all && document.getElementById ? true : false);
document.MM_returnValue = false; var imgURL = 'file:///' + field.value.replace(/\\/gi,'/');
if (!field.gp_img || (field.gp_img && field.gp_img.src != imgURL) || isNS6) {field.gp_img = new Image();
with (field) {gp_img.sizeLimit = sizeL*1024; gp_img.minWidth = minW; gp_img.minHeight = minH; gp_img.maxWidth = maxW; gp_img.maxHeight = maxH;
gp_img.saveWidth = saveW; gp_img.saveHeight = saveH; gp_img.onload = showImageDimensions; gp_img.src = imgURL; }
} else showImageDimensions(field.gp_img);}
}
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_validateForm() { //v4.0
var i,p,q,nm,test,num,min,max,errors='',args=MM_valida teForm.arguments;
for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
if (val) { nm=val.name; if ((val=val.value)!="") {
if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
} else if (test!='R') {
if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
min=test.substring(8,p); max=test.substring(p+1);
if (val<min || max<val) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
} } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
} if (errors) alert('The following error(s) occurred:\n'+errors);
document.MM_returnValue = (errors == '');
}
//-->
</script>
</head>
<body>
<form action="#" method="POST" name="form1" enctype="multipart/form-data" onSubmit="checkFileUpload(this,'GIF,JPG,PNG',false ,100,220,160,'440','320','220','160');return document.MM_returnValue;MM_validateForm('metri','' ,'RisNum','via','','R','citta','','R','descrizione ','','R');return document.MM_returnValue">
<table cellpadding="1" cellspacing="1">
<tr>
<td>Immagine:</td>
<td><input type="file" name="file" onChange="checkOneFileUpload(this,'GIF,JPG,PNG',fa lse,100,220,160,'440','320','220','160')"></td>
</tr>
<tr valign="baseline">
<td><input type="submit" value="Invia" name="submit"></td>
</tr>
</table>
</form>
</body>
</html>