Phonegap文件传输,无法正常工作。 imageuritoupload没有定义?

时间:2014-04-28 00:28:10

标签: javascript php android cordova

我试图从我的模拟器上传图片,但我在控制台中收到错误 processMessage失败:imageUriToUpload未定义。我按照http://docs.phonegap.com/en/3.2.0/cordova_file_file.md.html#FileTransfer

的指南进行了操作

所以我在这里空白,不知道如何解决这个问题。 uploadPhoto应该从capturePhoto方法获取imageURI。

在客户端捕获照片方法:

function capturePhoto() {
            navigator.camera.getPicture(
                uploadPhoto, 
                function(message) { alert("Failed to get picture"); },
                {
                    quality: 50,
                    destinationType: navigator.camera.DestinationType.FILE_URI,
                    sourceType: navigator.camera.PictureSourceType.PHOTOLIBRARY
                }
            );
        }

客户代码:

function uploadPhoto(imageURI) {
            var title1 = document.getElementById('title').value;
            var desc1 = document.getElementById('desc').value;

            var options = new FileUploadOptions();
            options.key = "file";
            options.fileName= imageURI.substr(imageURI.lastIndexOf('/')+1);
            options.mimeType= "image/jpeg";

            var params = new Object();
            params.title = title1;
            params.desc = desc1;

            options.params = params;
            options.chunkedMode = false;

            var ft = new FileTransfer();
            ft.upload(imageURI, encodeURI("http://lols.com/php"), win, fail, options);
        }

        function win(result) {
            console.log("Code = " + r.responseCode);
            console.log("Response = " + r.response);
            console.log("Sent = " + r.bytesSent);
            alert(r.response);
            window.location.replace("http://hp1.vlab.cs.hioa.no/Hovedprosjekt/public/mobileupload")
        }

        function fail(error) {
            alert("fail");
            console.log(evt.target.error.code);
        }

服务器代码:

<?php 
print_r($_FILES["file"]);

$a = storage_path().'/mobileupload/'.'yolo.jpg';
move_uploaded_file($_FILES["file"]["tmp_name"], $a);
?>

1 个答案:

答案 0 :(得分:0)

options.fileName= imageURI.substr(imageURI.lastIndexOf('/')+1);中发生错字修正,现在已经过了错误。