0
嘿傢伙我使用jQuery的,AJAX和HTML。這是我的上傳照片如何獲取圖像名稱上傳到服務器後在科爾多瓦
function uploadPhoto(imageURI) {
if (imageURI.substring(0,21)=="content://com.android") {
photo_split=imageURI.split("%3A");
imageURI="content://media/external/images/media/"+photo_split[1];
}
var options = new FileUploadOptions();
options.fileKey="file";
options.fileName=imageURI.substr(imageURI.lastIndexOf('/')+1);
//alert(options.fileName);
options.mimeType="image/jpeg";
var params = new Object();
params.value1 = "test";
params.value2 = "param";
options.params = params;
options.chunkedMode = false;
var ft = new FileTransfer();
ft.upload(imageURI, host+"/skripsitemplate/php/upload.php", win, fail, options);
}
function win(r) {
console.log("Code = " + r.responseCode);
console.log("Response = " + r.response);
console.log("Sent = " + r.bytesSent);
}
此代碼工作正常。但我不知道如何獲取已經上傳到服務器的圖像名稱。圖像名稱將被上傳到數據庫。這是我upload.php的
<?php
print_r($_FILES);
$new_image_name = "foto".rand(1,1000)."_".date("Y-m-d-h-i-s").".jpg";
move_uploaded_file($_FILES["file"]["tmp_name"], "../web/uploads/".$new_image_name);
echo $new_image_name;
?>
我真正關心科爾多瓦和PhoneGap的事情新手。謝謝你們,有一個愉快的一天
非常感謝你@Shadi Shaaban – Rei