Search Google

Sunday 28 July 2013

Browse file code

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>

<script >
    function imageURL(input) {
        if (input.files && input.files[0]) {
            var reader = new FileReader();
            reader.onload = function(e) {
                $('#preview_img').attr('src', e.target.result)
                 var max_size = 500;
 $("#preview_img").each(function(i) {
 if ($(this).height() > $(this).width()) {
 var h = max_size;
 var w = Math.ceil($(this).width() / $(this).height() * max_size);
 } else {
 var w = max_size;
 var h = Math.ceil($(this).height() / $(this).width() * max_size);
 }
 $(this).css({ height: h, width: w });
 });
             }
             reader.readAsDataURL(input.files[0]);
         }
    }
</script>
</head> 
 
 
<body>
<form>
  <p>
  <input type="file" name="data[Settings][pic]" size="42" onchange="imageURL(this)" id="SettingsPic">
  <br/><br/><br>
  <img id="preview_img" />
  </p>

</form>
</body>
</html> 
 
 

No comments:

Post a Comment