使用PHP进行文件传输Cordova [英] File-Transfer Cordova using php
本文介绍了使用PHP进行文件传输Cordova的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下代码
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时,我不知道如何保存,我的代码是这样的:
It's working, however when I send to my php I do not know how to save, my code this way:
<?php
move_uploaded_file($_FILES["file"]["tmp_name"], 'C:\xampp\htdocs\upload\images');
?>
我想保存在"C:\ xampp \ htdocs \ upload \ images"中,就像我的PHP一样?
I would like to save in 'C:\xampp\htdocs\upload\images', as should be my php?
推荐答案
可以按以下方式运行,但js确实如此
Could run as follows, the js was so
ft.upload(fileURI, encodeURI("http://192.168.0.102/upload/index.php"), app.win, app.fail, options);
index.php接收并将其发送到That Is上载的images文件夹中.
The index.php Receives and sends it to the images folder inside of That Is upload.
<?php
$new_image_name = strtolower($_FILES['file']['name']);
move_uploaded_file($_FILES["file"]["tmp_name"], "images/".$new_image_name);
这篇关于使用PHP进行文件传输Cordova的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文