我是手机缺口/ cordova和PHP的新手。 我创建了一个手机间隙/ cordova应用程序将相机拍摄的图像上传到服务器。服务器根据一些时间戳代码唯一地重命名图像,它必须将该图像名称返回给应用程序。我已经很好地上传了图像,但我需要检索回由服务器回送的图像名称数据。在成功上传时,当我试图提醒服务器返回的数据时,它正在警告[对象对象]。我需要检索值。如何是可能的。我在客户端的代码如下。
var pictureSource; // picture source var destinationType; // sets the format of returned value document.addEventListener("deviceready", onDeviceReady, false); function onDeviceReady() { pictureSource = navigator.camera.PictureSourceType; destinationType = navigator.camera.DestinationType; } function clearCache() { navigator.camera.cleanup(); } var retries = 0; function onCapturePhoto(fileURI) { var win = function (r) { clearCache(); retries = 0; alert('Done! message returned back is '+r); } var fail = function (error) { if (retries == 0) { retries ++ setTimeout(function() { onCapturePhoto(fileURI) }, 1000) } else { retries = 0; clearCache(); alert('Ups. Something wrong happens!'); } } var options = new FileUploadOptions(); options.fileKey = "file"; options.fileName = fileURI.substr(fileURI.lastIndexOf('/') + 1); options.mimeType = "image/jpeg"; var params=new param(); param.client_device_id=device.uuid; options.params = params; // if we need to send parameters to the server request var ft = new FileTransfer(); ft.upload(fileURI, encodeURI("http://host/upload.php"), win, fail, options); } function capturePhoto() { navigator.camera.getPicture(onCapturePhoto, onFail, { quality: 100, destinationType: destinationType.FILE_URI }); } function onFail(message) { alert('Failed because: ' + message); }upload.php的代码如下
<?php if (!file_exists($_POST["client_device_id"])) { mkdir($_POST["client_device_id"], 0777, true); } $date = new DateTime(); $timeStamp=$date->getTimestamp() -1435930688; move_uploaded_file($_FILES["file"]["tmp_name"], 'f:\\xampp\\htdocs\\FileUpload\\'.$_POST["client_device_id"]."\\".$timeStamp.'.jpg'); echo $timeStamp.".jpg"; ?>问题是,在设备成功上传后,它正在提示“完成! 返回的消息是[object object]'。我需要获取值。请帮助我。
I am new to phone gap/cordova and PHP. I created a phone gap/cordova application to upload camera taken image to server.The server uniquely renames the image according to some timestamp code and it has to return that image name back to the app.I have pretty well uploaded the image but I need to retrieve back that image name data echoed back by the server.On success upload, when I tried to alert the data that is returned back by the server, it is alerting [object object].I need to retrieve the value.How can it be possible.My code at the client side is given below.
var pictureSource; // picture source var destinationType; // sets the format of returned value document.addEventListener("deviceready", onDeviceReady, false); function onDeviceReady() { pictureSource = navigator.camera.PictureSourceType; destinationType = navigator.camera.DestinationType; } function clearCache() { navigator.camera.cleanup(); } var retries = 0; function onCapturePhoto(fileURI) { var win = function (r) { clearCache(); retries = 0; alert('Done! message returned back is '+r); } var fail = function (error) { if (retries == 0) { retries ++ setTimeout(function() { onCapturePhoto(fileURI) }, 1000) } else { retries = 0; clearCache(); alert('Ups. Something wrong happens!'); } } var options = new FileUploadOptions(); options.fileKey = "file"; options.fileName = fileURI.substr(fileURI.lastIndexOf('/') + 1); options.mimeType = "image/jpeg"; var params=new param(); param.client_device_id=device.uuid; options.params = params; // if we need to send parameters to the server request var ft = new FileTransfer(); ft.upload(fileURI, encodeURI("http://host/upload.php"), win, fail, options); } function capturePhoto() { navigator.camera.getPicture(onCapturePhoto, onFail, { quality: 100, destinationType: destinationType.FILE_URI }); } function onFail(message) { alert('Failed because: ' + message); }The code for the upload.php is given below
<?php if (!file_exists($_POST["client_device_id"])) { mkdir($_POST["client_device_id"], 0777, true); } $date = new DateTime(); $timeStamp=$date->getTimestamp() -1435930688; move_uploaded_file($_FILES["file"]["tmp_name"], 'f:\\xampp\\htdocs\\FileUpload\\'.$_POST["client_device_id"]."\\".$timeStamp.'.jpg'); echo $timeStamp.".jpg"; ?>The problem is that after successful upload in the device it is alerting 'Done! message returned back is [object object]'.I need to get the value.Please help me on it.
最满意答案
我自己想出答案。只想与大家分享。我使用了alert(JSON.stringify(r))。现在我知道了返回的json对象的格式。知道我已经轻松打印出图像名称了。 r.response帮助我检索生成的图像名称。
I figured out the answer myself.Just want to share with you all.I used alert(JSON.stringify(r)).Now I know the format of the returned json object .Knowing that I have easily printed out the image name.r.response helped me retrieve the generated image name.
更多推荐
var,upload,new,电脑培训,计算机培训,IT培训"/> <meta name="description&qu
发布评论