使用AJAX上传文件

I have the script:

#
    var xmlhttp;
    var params = "file=Not sure what is it";
    if (window.XMLHttpRequest){
        xmlhttp=new XMLHttpRequest();
    }
    else{
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function(){
        if(xmlhttp.readyState==4){
            if (xmlhttp.status==200)
                alert('Upload done');
            else
                alert('Error!!!');
        }
    }
    xmlhttp.open("POST", "http://localhost/ajax2.php", true);
    //Send the proper header information along with the request
    xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlhttp.setRequestHeader("Content-length", params.length);
    xmlhttp.setRequestHeader("Connection", "close");
    xmlhttp.send(params);
#

This script send a POST request to server, now I just wonder that how can I set params as a file content to upload?

You can't do this solely with JavaScript, for security reasons. Try SWFUpload, Uploadify, or similar. These are Flash-based solutions that you can interact with via JavaScript.

Look how this library does it