javascript if image
<p>so.. i have a XMLHttpRequest image uploader and <strong>i don't know how to limit the image uploader to only upload images nothing else</strong> and i have put a limit on the file size so its 3mb so its not too big</p>

<p><br /></p>

<p>question <strong>how do you limit the image  uploader to only upload images nothing else</strong></p>

<p>image uploader code </p>

<pre><code>    // following line is not necessary: prevents running on SitePoint servers
    if (location.host.indexOf("sitepointstatic") &gt;= 0) return

    var xhr = new XMLHttpRequest();
    if (xhr.upload &amp;&amp; file.type == ("image/jpg"||"image/png") &amp;&amp; file.size &lt;= $id("MAX_FILE_SIZE").value) {

        // create progress bar
        var o = $id("progress");
        var progress = o.appendChild(document.createElement("p"));
        progress.appendChild(document.createTextNode("upload " + file.name));


        // progress bar
        xhr.upload.addEventListener("progress", function(e) {
            var pc = parseInt(100 - (e.loaded / e.total * 100));
            progress.style.backgroundPosition = pc + "% 0";
        }, false);

        // file received/failed
        xhr.onreadystatechange = function(e) {
            if (xhr.readyState == 4) {
                progress.className = (xhr.status == 200 ? "success" : "failure");
            }
        };

        // start upload
        xhr.open("POST", "upload.php", true);           
        xhr.setRequestHeader("X_FILENAME", file.name);
        xhr.send(file);
    }
    else
    {
    alert("file in unsported at this time " + file.type);
    }
</code></pre>

<p>I just want to check their file extension just to be clear. <br />
Thanks for your help </p>
