// Create the record file and set variables fileURL and audioRecord //
//
audioRecord = 'record.wav';
document.addEventListener("deviceready", onDeviceReady, false);
// Cordova is ready
//
function onDeviceReady() {
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onFileSystemSuccess, fail);
}
function onFileSystemSuccess(fileSystem) {
fileSystem.root.getFile(audioRecord, {
create: true,
exclusive: false
}, gotFileEntry, fail);
}
function gotFileEntry(fileEntry) {
fileURL = fileEntry.toURL();
}
function fail(fileSystem) {
alert("File System Error");
}
// Start recording and stop after 10 seconds //
//
function recordAudio() {
var record = new Media(audioRecord, onSuccess, onError);
// Record audio
record.startRecord();
// Stop recording
var recTime = 0;
var recInterval = setInterval(function() {
recTime = recTime + 1;
setAudioPosition(recTime + " sec");
if (recTime >= 10) {
clearInterval(recInterval);
record.stopRecord();
}
}, 1000);
}
// Cordova is ready
//
function onDeviceReady() {
recordAudio();
}
// onSuccess Callback
//
function onSuccess() {
alert("recordAudio():Audio Success");
uploadAudio();
}
// onError Callback
//
function onError(error) {
alert('code: ' + error.code + '\n' +
'message: ' + error.message + '\n');
}
// Set audio position
//
function setAudioPosition(position) {
document.getElementById('audio_position').innerHTML = position;
}
// Upload the recorded file to server //
//
function uploadAudio(fileURL) {
var options = new FileUploadOptions();
options.fileKey = "file";
options.fileName = "recordupload.wav";
options.mimeType = "audio/wav";
var ft = new FileTransfer();
ft.upload(fileURL, encodeURI("http://www.xylo-app.com/images/test/i..."), win, fail, options);
}
function win(r) {
console.log("Code = " + r.responseCode);
console.log("Response = " + r.response);
console.log("Sent = " + r.bytesSent);
alert("success!");
}
function fail(error) {
alert("An error has occurred: Code = " + error.code);
console.log("upload error source " + error.source);
console.log("upload error target " + error.target);
}
<?php
print_r($_FILES);
move_uploaded_file($_FILES["file"]["tmp_name"], "/home/xyloappc/public_html/images/test/uploads/".$_FILES["file"]["name"]);
?>