You can actually get both physical size and dimensions....using the image
object in JS...see below.

"Checking a selected image's dimensions is possible with IE4+ (and 
probably with NN3 though I haven't tried), simply be creating an Image
object and checking its dimensions. NN4 had a security hole by allowing
http: loaded pages to open local file: urls thus nowadays you can't from a
web page create an Image 
object with a local file: url src unless your script is trusted to do so.

See http://www.faqts.com/knowledge-base/view.phtml/aid/840/fid/125/lang/en
on running trusted scripts with NN4.

Checking a selected file's size requires local file system access which 
is usually for web pages not possible due to security considerations. 
If security settings are low enough NN4 can call into Java to read the 
file's size, IE4+ can use the FileSystemObject to check the file's size.

The following page has two functions
  getFileSize 
and
  getImageDimension 
containing NN4 and IE4+ code to solve the described tasks. "


<HTML>
<HEAD>
<SCRIPT>
function getImageDimension (imgURL, loadHandler) {
  var img = new Image();
  img.onload = loadHandler;
  if (document.layers 
      && location.protocol.toLowerCase() != 'file:' 
      && navigator.javaEnabled())
    netscape.security.PrivilegeManager.enablePrivilege(
      'UniversalFileRead'
    );
  img.src = imgURL;
}
function getFileSize (fileName) {
  if (document.layers) {
    if (navigator.javaEnabled()) {
      var file = new java.io.File(fileName);
      if (location.protocol.toLowerCase() != 'file:')
        netscape.security.PrivilegeManager.enablePrivilege(
        'UniversalFileRead'
        );
      return file.length();
    }
    else return -1;
  }
  else if (document.all) {
    window.oldOnError = window.onerror;
    window.onerror = function (err) {
      if (err.indexOf('utomation') != -1) {
        alert('file access not possible');
        return true;
      }
      else 
        return false;
    };
    var fso = new ActiveXObject('Scripting.FileSystemObject');
    var file = fso.GetFile(fileName);
    window.onerror = window.oldOnError;
    return file.Size;
  }
}
function showImageDimensions () {
  alert(this.width + 'x' + this.height);
}
</SCRIPT>
<SCRIPT>
function checkImageDimensions (fileName) {
  var imgURL = 'file:///' + fileName;
  getImageDimension(imgURL, showImageDimensions);
}
</SCRIPT>
</HEAD>
<BODY>
<FORM NAME="formName">
<INPUT TYPE="file" NAME="fileName">
<BR>
<INPUT TYPE="button" VALUE="check file size"
       ONCLICK="alert(getFileSize(this.form.fileName.value))"
>
<BR>
<INPUT TYPE="button" VALUE="check image dimensions"
       ONCLICK="checkImageDimensions(this.form.fileName.value)"
>
</FORM>
</BODY>
</HTML>



HTH

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Introducing the Fusion Authority Quarterly Update. 80 pages of hard-hitting,
up-to-date ColdFusion information by your peers, delivered to your door four 
times a year.
http://www.fusionauthority.com/quarterly

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:258433
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4

Reply via email to