Show Image Before Upload

Show Image Before Upload:


Example :1

show image before upload</title>
function showimage(ele)


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

Example : 2

<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].onload=function() {alert(‘path = ‘+
‘\nimage width = ‘+document.images[img].width+’px’+
‘\nimage height = ‘+document.images[img].height+’px’)};

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


Example :3

  .thumb {
    height: 75px;
    border: 1px solid #000;
    margin: 10px 5px 0 0;

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

  function handleFileSelect(evt) {
    var 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.*’)) {

      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=”‘,,
                            ‘” title=”‘, escape(, ‘”/>’].join(”);
          document.getElementById(‘list’).insertBefore(span, null);

      // Read in the image file as a data URL.

  document.getElementById(‘files’).addEventListener(‘change’, handleFileSelect, false);






8 thoughts on “Show Image Before Upload

Leave a Reply

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

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

Google photo

You are commenting using your Google 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 )

Connecting to %s