dovercomputers
asked on
Image upload using jqmobile & phonegap
Hi Experts,
I am having major problems, and having searched the net cannot find an example or tutorial that I can get working with my code.
I am writing an app for IOS & Android using dreamweaver 5.5 / jqmobile / phonegap. In one of the forms, I need to be able to upload photo's. I have it working that you can select an image from the gallery or take a new photo and it appears in the form.
What I need to happen is that the image is sent to the webserver, and this is where I am well and truly stuck.
Here is the JS
The part of the form that calls the camera function and then displays a thumbnail
So its all working to this point.
Now I am stuck!
I was thinking add to the JS something along the lines of
Would that work and if so what would I need to put in the upload.php file to retrieve the image?
If not can someone possibly give me a working example of how to do it?
Ideally, I want to name/number the images sequentially so that server side when the claim form is uploaded the script can then scan the directory and pickup the correct images to store in the DB with the rest of the form.
Thanks for reading
Jim
I am having major problems, and having searched the net cannot find an example or tutorial that I can get working with my code.
I am writing an app for IOS & Android using dreamweaver 5.5 / jqmobile / phonegap. In one of the forms, I need to be able to upload photo's. I have it working that you can select an image from the gallery or take a new photo and it appears in the form.
What I need to happen is that the image is sent to the webserver, and this is where I am well and truly stuck.
Here is the JS
<script type="text/javascript" charset="utf-8">
var pictureSource; // picture source
var destinationType; // sets the format of returned value
// Wait for PhoneGap to connect with the device
function onLoad() {
document.addEventListener("deviceready",onDeviceReady,false);
}
// PhoneGap is ready to be used!
function onDeviceReady() {
pictureSource=navigator.camera.PictureSourceType;
destinationType=navigator.camera.DestinationType;
}
function getPicture(sourceType)
{
var options = { quality: 10 };
if (sourceType != undefined) {
options["sourceType"] = sourceType;
}
// if no sourceType specified, the default is CAMERA
navigator.camera.getPicture(getPicture_Success, null, options);
};
function getPicture_Success(imageData)
{
//alert("getpic success");
document.getElementById("smallImage").src = "data:image/jpeg;base64," + imageData;
}
</script>
The part of the form that calls the camera function and then displays a thumbnail
<div data-role="collapsible" data-collapsed="true">
<h3>Photographs</h3>
<p>Please upload your photographs</p>
<div data-role="controlgroup" data-type="horizontal"><a href="#" data-role="button" data-icon="plus" data-iconpos="right" onclick="getPicture(pictureSource.PHOTOLIBRARY);">Gallery Photo</a><a href="#" data-role="button" data-icon="plus" data-iconpos="right" onclick="getPicture();">New Photo</a>
<img style="width:60px;height:60px;" id="smallImage" src="" />
</div>
</div>
So its all working to this point.
Now I am stuck!
I was thinking add to the JS something along the lines of
function getPicture_Success(imageData)
{
//alert("getpic success");
document.getElementById("smallImage").src = "data:image/jpeg;base64," + imageData;
var imageName = "data:image/jpeg;base64," + imageData;
$.ajax({
type: "POST",
url: "http://quote-sys.co.uk/ClaimApp/upload.php",
data: "image="+ imageName,
success: function(){
$('div.successUpload').fadeIn();
}
});
}
Would that work and if so what would I need to put in the upload.php file to retrieve the image?
If not can someone possibly give me a working example of how to do it?
Ideally, I want to name/number the images sequentially so that server side when the claim form is uploaded the script can then scan the directory and pickup the correct images to store in the DB with the rest of the form.
Thanks for reading
Jim
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.