使用php进行文件传输Cordova
我有以下代码使用php进行文件传输Cordova,cordova,phonegap-plugins,file-transfer,cordova-plugins,Cordova,Phonegap Plugins,File Transfer,Cordova Plugins,我有以下代码 onDeviceReady: function () { navigator.camera.getPicture( app.uploadPhoto, function (message) { alert('get picture failed'); }, { quality: 50, dest
onDeviceReady: function () {
navigator.camera.getPicture(
app.uploadPhoto,
function (message) { alert('get picture failed'); },
{
quality: 50,
destinationType: navigator.camera.DestinationType.FILE_URI,
sourceType: navigator.camera.PictureSourceType.PHOTOLIBRARY
}
);
},
uploadPhoto: function(imageURI) {
var options = new FileUploadOptions();
options.fileKey="file";
options.fileName=imageURI.substr(imageURI.lastIndexOf('/')+1);
options.mimeType="image/jpeg";
var params = {};
params.value1 = "test";
params.value2 = "param";
options.params = params;
var ft = new FileTransfer();
ft.upload(imageURI, encodeURI("http://192.168.0.101/upload/index.php"), app.win, app.fail, options);
},
win: function(r) {
console.log("Code = " + r.responseCode);
console.log("Response = " + r.response);
console.log("Sent = " + r.bytesSent);
},
fail: function(error) {
alert("An error has occurred: Code = " + error.code);
console.log("upload error source " + error.source);
console.log("upload error target " + error.target);
},
它可以工作,但是当我发送到我的php时,我不知道如何保存我的代码:
<?php
move_uploaded_file($_FILES["file"]["tmp_name"], 'C:\xampp\htdocs\upload\images');
?>
我想保存在“C:\xampp\htdocs\upload\images”中,就像我的php一样?可以如下运行,js是这样的
ft.upload(fileURI, encodeURI("http://192.168.0.102/upload/index.php"), app.win, app.fail, options);
php接收并将其发送到该文件夹中的images文件夹,然后进行上载
<?php
$new_image_name = strtolower($_FILES['file']['name']);
move_uploaded_file($_FILES["file"]["tmp_name"], "images/".$new_image_name);