Validate Image Dimension

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vishnuvarthan
    New Member
    • Jan 2007
    • 5

    #1

    Validate Image Dimension

    I want to validate the dimension of the uploading image. The dimension must be 289x66. Please find below my code.

    var img = new Image(); img.src=documen t.forms[0].btnUploadLogo. value;
    //btnUploadLogo is input file button ID...
    if (img.width != 289 || img.height != 66)
    {
    // Error Message or Alert
    }

    But i am getting width and height as 0 and 0. I am using IE 7.0.

    Thank in advance
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    First of all, test it on an image that already exists on the server. If that works, then test with an uploaded image. Is the code for an uploaded image or for the page which contains the uploading form?

    If the image has not yet been uploaded, your code should not work because javascript should not be able to access local files.

    Comment

    • vishnuvarthan
      New Member
      • Jan 2007
      • 5

      #3
      That form uploads the image. I need to validate the image dimension before uploading. Is it possible.

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        Javascript is not supposed to be able to access files on the local server. Unfortunately, as ever, IE (in previous versions at least) could access local files. I don't know about IE7, but they may have fixed the security hole.

        Comment

        • vishnuvarthan
          New Member
          • Jan 2007
          • 5

          #5
          Ok..Thank u for ur reply....

          Comment

          Working...