"Jon Hall" <[EMAIL PROTECTED]> wrote in message news:016501c15d87$53a9a740
> I dont think it is possible with javascript. In order for this to be true,
> either the script would need access to the local filesystem, which it does
> not...or the browser would store the filesize of the selected file
somewhere
> accessible in the dom. That would be a very cool thing for the browser's
to
> do, but I have never heard of this, so I very much doubt that is true
> either.

It's feasible, even if it's quite an hack. It works only on IE and NN 6, no
NN 4. It doesn't works on the Mac either (but fails silentely in both
cases). I made a Dreamweaver behavior for this, below is a sample code, hope
OE will not do bad things with it:

<html>
<head>
<title>Check File Upload</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript">
<!--
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 tmt_checkImgObj(){//v2.0
 var errorMsg="";
 if(this.maxS!=""&&this.fileSize/1000>this.maxS){
  errorMsg+="Maximum size for images is: "+this.maxS+" kilobytes \n";}
 if(this.minS!=""&&this.fileSize/1000<this.minS){
  errorMsg+="Minimum size for images is: "+this.minS+" kilobytes \n";}
 if(this.maxW!=""&&this.width>this.maxW){
  errorMsg+="Maximum width allowed for images is: "+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+="Maximum height allowed for images is: "+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){//v
2.0
 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.s
rc=imgURL;
}

function
tmt_CheckImg(formElement,minW,maxW,minH,maxH,minS,maxS,mime,fW,fH){//v2.0
 document.MM_returnValue=true;if(document.getElementById){var
obj=MM_findObj(formElement);
 var f=obj.form.name;if(obj&&f){var imgRex=new
RegExp("\\.("+mime+")$","i");if(imgRex.test(obj.value)){
 var
imgURL="file:///"+obj.value;tmt_createImgObj(imgURL,tmt_checkImgObj,minW,max
W,minH,maxH,minS,maxS,fW,fH);

eval("setTimeout(\"if(document.MM_returnValue){document."+f+".submit()}\",30
0)");}
 else{document.MM_returnValue=false;alert("Only "+mime+" files are
allowed");obj.focus();obj.select();}}}
}
//-->
</script>
</head>

<body bgcolor="#FFFFFF">
<form name="form1" enctype="multipart/form-data" method="post" action=""
onSubmit="tmt_CheckImg('fileField','100','200','150','250','5','30','jpg|gif
','','');return document.MM_returnValue">
  <p>
    <input type="file" name="fileField">
  </p>
  <p>
    <input type="submit" name="Submit" value="Submit">
  </p>
</form>
</body>
</html>


For a tutorial on how to use a set of Ultradev extensions for file upload
check:

http://www.carolinawebsolutions.com/cffileupload/



----------------------------
Massimo Foti
[EMAIL PROTECTED]

http://www.massimocorner.com
Dreamweaver, Ultradev and Fireworks goodies

http://www.projectseven.com/viewer/snippets.htm
Snippets Panel
----------------------------


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at 
http://www.fusionauthority.com/bkinfo.cfm
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to