<html>
<head>
<script language="javascript" src="jquery.js"></script>
<script type="text/javascript">
var reader = new FileReader();

function preview(what) {
     if(jQuery.browser.msie || jQuery.browser.safari || jQuery.browser.chrome) {
         document.getElementById("prevImage").src=what.value;
         return;
    }
    else{                   
        // array with acceptable file types
        var accept = ["image/png","image/jpeg","image/jpg","image/gif"];

        // if we accept the first selected file type
        if (accept.indexOf(what.files[0].type) > -1) {
            if(what.files && what.files[0]){
                  reader.readAsDataURL(what.files[0]);
                  document.getElementById("prevImage").src=reader.result;
            }
        }       
    }
}
</script>
</head>
<body>
<form>
<input type='file' name='file' accept='image/gif,image/jpeg,image/png,image/jpg'  id='file' onchange='preview(this)'>
<div id="prevImage"><div/>
</form>
</body>
</html>