req = new XMLHttpRequest();
url="http://localhost/my/upload/upf.php";
sepcode="AaB3x";
sep="--"+sepcode;
crlf="rn";
// begin
fbody =sep+crlf;
// input
fbody+="Content-Disposition: form-data; name=\"field1\""+crlf+crlf;
fbody+="test field 1"+crlf;
fbody+=sep;
// file testo
fbody+=crlf;
fbody+="Content-Disposition: attachment; name=\"file1\"; filename=\"prova.txt\""+crlf;
fbody+="Content-Type: text/plain"+crlf+crlf;
fbody+="contenuto del file"+crlf;
fbody+=sep;
//file binario, un gif
fbody+=crlf;
fbody+="Content-Disposition: attachment; name=\"file2\"; filename=\"smile.gif\""+crlf;
fbody+="Content-Transfer-Encoding: base64"+crlf;
fbody+="Content-Type: image/gif"+crlf+crlf;
fbody+="R0lGODlhDgAOAKEAAAAAAP//AL+/vwAAACH5BAEAAAIALAAAAAAOAA4AAAIqlI+JwKDGggwsgYnpopdrKEXe12WTI1zlSYZYh6ZhE27md4jzkzb8bygAADs";
fbofy+=crlf;
// end
//fbody+=sep;
req.open("POST",url,false);
req.setRequestHeader("Content-type", "multipart/form-data,boundary="+sepcode);
req.setRequestHeader("Content-Length", fbody.length);
req.send(fbody);

