I want to upload a photo using the PhoneGap API. The FileTransfer object is basically what I want because I want to upload a photo but then I want to include some basic information about the user as well such as their user ID so that I can store it as their’s. My code is as follows and this is basically coming from the PhoneGap API but with my additions
<html><head><script>function uploadPhotoandID(imageURI, userID) {
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://some.server.com/upload.php", win, fail, options);
ft.upload(userID, "http://some.server.com/upload.php", win, fail, options);
}</script></head>
<body><button onclick="uploadPhotoandID(imageURI, userID)">Click me</button></body</html>
Do I need those parameters in the function in HTML like that? and is it able to retrieve those variables even though they are in the script in the header?
If you see any other errors please let me know!
Right so all you want to do is instead of:
you would:
Now you don’t have to make two calls to “upload”. The userID parameter will be available as:
in your PHP script.