我正在尝试连接照片以上传到服务器..没有cordova 1.7.0示例..只是尝试一下,但它不起作用。我的错误是.. wait_fences:未能收到回复:10004003。
function capturePhoto() {
// Take picture using device camera and retrieve image as base64-encoded string
navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 50,
destinationType: destinationType.DATA_URL });
}
// A button will call this function
//
function getPhoto(source) {
// Retrieve image file location from specified source
navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 50,
destinationType: destinationType.FILE_URI,
sourceType: source });
}
function onSuccess(imageData) {
var image = document.getElementById('myImage');
image.src = "data:image/jpeg;base64," + imageData;
$.post('http://site.com/api/upload.php', {data:imageData});
}
<?php
if ($_REQUEST['image']) {
// convert the image data from base64
$imgData = base64_decode($_REQUEST['image']);
// set the image paths
$file = '/api/' . md5(date('Ymdgisu')) . '.jpg';
$url = 'http://www.site.com' . $file;
// delete the image if it already exists
if (file_exists($file)) { unlink($file); }
// write the imgData to the file
$fp = fopen($file, 'w');
fwrite($fp, $imgData);
fclose($fp);
}
?>