Display image selected for uploading before upload not working
<p>I am trying to display an image after selecting from the hard drive before. I found a small code on <a href="http://jsfiddle.net/PrNWY/13/" rel="nofollow">this</a> website, I copy pasted it but it's not working (it is on the demo page). I can select an image and it's name is displayed to the right of the Choose File button, but neither the image nor the size is displayed. I am pulling my hairs out. </p>

<p>Whole code:</p>

<pre><code>&lt;!DOCTYPE html&gt;  &lt;!-- Using margin:auto will not work in IE8, unless a !DOCTYPE is declared. --&gt;
&lt;html lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://ogp.me/ns/fb#"&gt;

 &lt;head&gt;
    &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;

    &lt;link href="design3.css" rel="stylesheet" type="text/css"/&gt;

    &lt;script src="jquery-1.8.3.min.js"&gt;&lt;/script&gt;

&lt;script language="JavaScript"&gt;

// Handle file while select a new file
$('#file').change(function () {
    $('#img_size').val((this.files[0].size) / 1000000);
    handleFiles(this.files);
});


// handle files
function handleFiles(files) {
    for (var i = 0; i &lt; files.length; i++) {
        var file = files[i];
        var imageType = /image.*/;
        if (!file.type.match(imageType)) {
            continue;
        }
        var img = document.getElementById('fake_img');
       /* img.src = file;
        img.onload = function () {
        }; */
        var reader = new FileReader();
        reader.onload = (function (aImg) {
            return function (e) {
                aImg.src = e.target.result;
            };
        })(img);
        reader.readAsDataURL(file);
    }
}



function drawAd() 
{
    window.open('http://www.google.com');
}

&lt;/script&gt;

&lt;/head&gt;
&lt;body&gt; 

    &lt;input type="file" id="file"/&gt;
    &lt;input type="text" id="img_size" /&gt;
    &lt;img src="" id="fake_img" /&gt;

    &lt;button type="button" onclick="drawAd()"&gt;Refresh&lt;/button&gt;


&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>Tested in IE and Chrome.</p>
