codice:
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_findObj(n, d) {
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 tmt_checkImgObj(){
var errorMsg="";
if(this.maxS!=""&&this.fileSize/1000>this.maxS){
errorMsg+="peso massimo: "+this.maxS+" kilobytes \n";}
if(this.minS!=""&&this.fileSize/1000<this.minS){
errorMsg+="peso minimo: "+this.minS+" kilobytes \n";}
if(this.maxW!=""&&this.width>this.maxW){
errorMsg+="lunghezza massima ammessa: "+this.maxW+" pixels \n";}
if(this.minW!=""&&this.width<this.minW){
errorMsg+="Minimum width allowed for images is: "+this.minW+" pixels \n";}
if(this.maxH!=""&&this.height>this.maxH){
errorMsg+="altezza massima consentita: "+this.maxH+" pixels \n";}
if(this.minH!=""&&this.height<this.minH){
errorMsg+="Minimum height allowed for images is: "+this.minH+" pixels \n";}
if(errorMsg==""){
if(this.fW){var fW=MM_findObj(this.fW);if(fW){fW.value=this.width;}}
if(this.fH){var fH=MM_findObj(this.fH);if(fH){fH.value=this.height;}}}
else{alert(errorMsg);}document.MM_returnValue=(errorMsg=="");
}
function tmt_createImgObj(imgURL,loadHandler,minW,maxW,minH,maxH,minS,maxS,fW,fH){
document.MM_returnValue=false; var img=new Image();img.minW=minW;img.maxW=maxW;img.minH=minH;img.maxH=maxH;
img.fW=fW;img.fH=fH;img.minS=minS;img.maxS=maxS;img.onload=loadHandler;img.src=imgURL;
}
function tmt_CheckImg(formElement,minW,maxW,minH,maxH,minS,maxS,mime,fW,fH){
document.MM_returnValue=true;if(document.getElementById){var obj=MM_findObj(formElement);
var f=obj.form.name;if(obj&&f){var exRex=new RegExp("\\.("+mime+")$","i");
var noWhiteRex=/\\[\w_]*\.(\w{3})$/i;if(exRex.test(obj.value)&&noWhiteRex.test(obj.value)){
var imgURL="file:///"+obj.value;tmt_createImgObj(imgURL,tmt_checkImgObj,minW,maxW,minH,maxH,minS,maxS,fW,fH);
eval("setTimeout(\"if(document.MM_returnValue){document."+f+".submit()}\",300)");}
else{document.MM_returnValue=false;alert("solo file "+mime+" senza spazi vuoti sono ammessi");
obj.focus();obj.select();}}}
}
//-->
</script>
e poi sul campo:
<input name="foto" type="file" id="foto" onChange="tmt_CheckImg('foto','1','100','1','100','1','300','jpg|jpeg|gif','','');return document.MM_returnValue">