您不能在 Phonegap 上使用输入文件。不支持。你需要做这样的事情:
<div ng-click="selectPicture()">selectPicture</div> // Put own HTML format but call the fuction
// Angular fuction
$scope.selectPicture = function () {
var srcType = Camera.PictureSourceType.SAVEDPHOTOALBUM;
var options = {
// Some common settings are 20, 50, and 100
quality: 50,
destinationType: Camera.DestinationType.FILE_URI,
// In this app, dynamically set the picture source, Camera or photo gallery
sourceType: srcType,
encodingType: Camera.EncodingType.JPEG,
mediaType: Camera.MediaType.PICTURE,
allowEdit: true,
correctOrientation: true //Corrects Android orientation quirks
}
navigator.camera.getPicture(function cameraSuccess(imageUri) {
MobileUploadFile(imageUri);
}, function cameraError(error) {
console.debug("Unable to obtain picture: " + error, "app");
}, options);
}
function MobileUploadFile(imageURI) {
//console.log(imageURI);
var options = new FileUploadOptions();
options.fileKey = "file";
options.fileName = imageURI.substr(imageURI.lastIndexOf('/') + 1);
options.mimeType="image/jpeg";
options.chunkedMode = false;
var ft = new FileTransfer();
ft.upload(imageURI, encodeURI("http://www.example.com/upload.php"), function(result){
//console.log(JSON.stringify(result));
}, function(error){
//console.log(JSON.stringify(error));
}, options);
};
// php file
<?php
// Directory where uploaded images are saved
$dirname = "uploads/";
// If uploading file
if ($_FILES) {
print_r($_FILES);
mkdir ($dirname, 0777, true);
move_uploaded_file($_FILES["file"]{"tmp_name"],$dirname."/".$_FILES["file"]["name"]);
}
?>