Show Image Before Upload


Show Image Before Upload:

 

Example :1

<html>
<head>
<title>
show image before upload</title>
<script>
function showimage(ele)
{
document.ims.show.src=ele.value;
}
</script>

</head>

<body>
<form name=”ims” method=”POST”>
<input type=”file” name=”image” onChange = “return showimage(this)”>
<input type=”submit”>
<img id=”show”>
</form>
</body>
</html>

Example : 2

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″>
<script language=javascript>
function ImageArray(file, img) {
var thisImage = new Image();
thisImage.src = file.value;
document.images[img].src=thisImage.src;
document.images[img].onload=function() {alert(‘path = ‘+
document.images[img].src+
‘\nimage width = ‘+document.images[img].width+’px’+
‘\nimage height = ‘+document.images[img].height+’px’)};
}
</script>
</head>

<body>
<form name=”form1″ method=”post” action=””>
<p>
<input name=”myFile” type=”file” onchange=”ImageArray(myFile,’img1′)”>
<img id=”img1″ name=”img1″ src=””>

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

Example :3

<style>
  .thumb {
    height: 75px;
    border: 1px solid #000;
    margin: 10px 5px 0 0;
  }
</style>

<input type=”file” id=”files” name=”files[]” multiple />
<output id=”list”></output>

<script>
  function handleFileSelect(evt) {
    var files = evt.target.files; // FileList object

    // Loop through the FileList and render image files as thumbnails.
    for (var i = 0, f; f = files[i]; i++) {

      // Only process image files.
      if (!f.type.match(‘image.*’)) {
        continue;
      }

      var reader = new FileReader();

      // Closure to capture the file information.
      reader.onload = (function(theFile) {
        return function(e) {
          // Render thumbnail.
          var span = document.createElement(‘span’);
          span.innerHTML = [‘<img src=”‘, e.target.result,
                            ‘” title=”‘, escape(theFile.name), ‘”/>’].join(”);
          document.getElementById(‘list’).insertBefore(span, null);
        };
      })(f);

      // Read in the image file as a data URL.
      reader.readAsDataURL(f);
    }
  }

  document.getElementById(‘files’).addEventListener(‘change’, handleFileSelect, false);
</script>

 

–Venugopal

 

 

 

Advertisements

8 thoughts on “Show Image Before Upload

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s