I'm trying to send a picture with phonegap on

2019-09-08 08:41发布

I'm trying to send a picture, taken in my application, to my remote server using javascript and php, but so far I'm stuck:

This is the code from my application

function onPhotoDataSuccess(imageData) {
    alert(imageData);// returns:"/CapturedImagesCache/WP_20130605_021.jpg"
    //send picture to server
    var options = new FileUploadOptions();
    options.fileKey="file";
    options.fileName=imageData.substr(imageData.lastIndexOf('/')+1);
    options.mimeType="image/jpeg";

    var params = new Object();
    params.value1 = "test";
    params.value2 = "param";

    options.params = params;

    var ft = new FileTransfer();
    ft.upload(imageData, "http://***.**/app/upload/upload.php", win, fail, options);
    alert ("picture will be send");
}

The PHP server is running:

$new_image_name = "YEAH.jpg";
move_uploaded_file($_FILES["file"]["tmp_name"],"/httpdocs/app/upload/images/".$new_image_name);

And this is the error I'm getting:

Log:"Error in error callback: FileTransfer1933815797 = ReferenceError: Invalid left-hand side in assignment"

I really hope anyone has any experience with this, as this is for a school project which is due in 2 weeks.

1条回答
爷的心禁止访问
2楼-- · 2019-09-08 09:10

The problem wich i found was that i was calling to a chache location, due to that fact i was not able to send the image with ajax.

The way i solved this was to not send the image at all, i used the base64 encoding to paste it into a canvas in wich i was able to get the average color from the image after that i was able to send the values to my server.

i will add my code snippets soon

查看更多
登录 后发表回答