开发者

how to send binary strings with ajax to php - including html5 file api - blob slice

what i'm trying to do is uploading a file, slice it into 3 parts and give each one to different databases, so i can excess it later by connecting all parts.

the only trouble i have is sending the binary-string to php so i can write it to my databases. i have no clew what setting the content-type header to etc. althrough lots of other people seem to have a similar problem, i couldn't find any satisfying solution.

any help?

CODE/

index.php

<input type="file" id="file" name="file" onchange="filesProcess(this.files)" /><br/>

javascript

function filesProcess(files) {

for (i = 0; i<files.length;i++){    

var file = files[i];
var users = 3;  
var abschnitt = file.size/users;


var start = 0;
for (var z = 1; z<=users; z++){
    sliceFiles(z, users, start, file, abschnitt);
start = start + abschnitt + 1;
    }


 }
}







function sliceFiles(z, users, start, file, abschnitt) {
var reader = new FileReader();
var blob = file.slice(start, abschnitt);
reader.readAsBinaryString(blob);
reader.onloadend = function(evt) {  
var contentfile = evt.target.result;
    upload(z, users, contentfile);

    }
}








function upload(z, users, contentfile) {

xhr = new XMLHttpRequest();
xhr.onreadystatechange=function(){
if (xhr.readyState==4 && xhr.status==200)
    {
        $("#output").html(xhr.responseText);
    }
}

if (z == 1){
xhr.open("POST","upload_1.php",true);
}
if (z == 2){
xhr.open("POST","upload_2.php",true);
}
if (z == 3){
xhr.open("POST","upload_3.php",true);
}

xhr.setRequestHeader("Content-type", "multipart/form-data");
xhr.send开发者_JAVA技巧("inhalt="+contentfile);




}


Are you trying to send the blob as a string? Anyway, maybe the link below is helpful. It's about a chunked file uploader for Google Gears, I've implemented a similar solution a while back when Gears was still hot. The new JS File API implementation isn't that different, so I reckon you could modify the solution to fit your needs (and for use with the new JS File Api).

http://perplexed.co.uk/549_gears_multiple_file_upload.htm

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜