我正在使用Phonegap和Framework 7创建此应用。 在我的一个观点中,我想要一个图像上传按钮,我实现了以下代码:
<script>
function selectPhoto() {
// Retrieve image file location from specified source
navigator.camera.getPicture(uploadPhoto,
function(message) { alert('get picture failed'); },
{ quality: 50,
destinationType: navigator.camera.DestinationType.FILE_URI,
sourceType: navigator.camera.PictureSourceType.PHOTOLIBRARY, }
);
}
function uploadPhoto(imageURI) {
var options = new FileUploadOptions();
options.fileKey="file";
options.fileName=imageURI.substr(imageURI.lastIndexOf('/')+1);
options.mimeType="image/jpeg";
var params = new Object();
params.value1 = "test";
params.value2 = "param";
options.params = params;
var ft = new FileTransfer();
ft.upload(imageURI, "http://pedrofidalgo.pt/upload.php", win, fail, options);
}
function win(r) {
console.log("Code = " + r.responseCode);
console.log("Response = " + r.response);
console.log("Sent = " + r.bytesSent);
}
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);
}
</script>
<button class="btngaleria" onclick="selectPhoto();" style="margin-top:3vh; background-color: #5f919d;"> Upload image </button>
然后我在Web服务器上有一个带有以下代码的php文件:
<?php
print_r($_FILES);
$new_image_name = $_FILES["file"]["name"];
move_uploaded_file($_FILES["file"]["tmp_name"], "/uploads/sitios".$new_image_name);
?>
我尝试构建APK,当我点击按钮时,它根本不做任何事情。当我在浏览器中试用该应用程序时,控制台说我没有定义使用按钮(selectPhoto)调用的功能..有人可以提供一些指导吗?
答案 0 :(得分:0)
您的代码中有错误
function fail(error)
{
alert("An error has occurred: Code = " = error.code);
应该是
function fail(error)
{
alert("An error has occurred: Code = " + error.code);