Joby_1 0 Newbie Poster
Now i can check the size of the image. But can't validate the image type(.jpg, gif etc..). Could you please check the following my code and give answer.



<!--Form image validation--> <script type="text/javascript" src="js/jQuery-1.4.1-min.js"></script> <script>
$(document).ready(function(){
$('#i_submit').click( function() {
    //check whether browser fully supports all File API

    {
        //get the file size, file type and file name from file input field
        var fsize = $('#i_file')[0].files[0].size;
        var fname = $('#i_file')[0].files[0].name;

        if(fsize>2000000) //do something if file size more than 1 mb (1048576)
        {
            alert("Image is too big! Please select an image with  below 1 MB size.");
            return false;
        }else{
            alert("You are good to go!");
        }


        var ftype = $('#i_file')[0].files[0].type;

        switch(ftype.substring(ftype.lastIndexOf('.') + 1).toLowerCase()){
        case 'gif': case 'jpg': case 'png':
            alert("an image");
            break;
        default:
            $('#i_file')[0].files[0].type;
            // error message here
            alert("not an image");
            break;

        }


    }else{
        alert("Please upgrade your browser, because your current browser lacks some new features we need!");
    }
      });
});


</script> <!--Form--> <form name="form" action="index.php" method="post" enctype="multipart/form-data"> <table> <input name="picture" type="file" value="" id="i_file" /> <!--<input name="Submit" type="button" value="Submit" id="i_submit" />--> <input name="Submit" type="image" value="Submit" id="i_submit" /> </table> </form>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.