Calculating Machine Calculating Machine - 4 months ago 25
Javascript Question

cordova: image upload not working

I am using cordova file upload plugin to upload image. I am trying to upload image from gallery to server but due to some reason file is not uploading to server.

Here is the js code.

function uploadImage() {
document.getElementById('picture_msg').innerHTML = "";
// Get URI of picture to upload
function(uri) {
try {
// Pick image from div
var img = document.getElementById('pimage'); = "visible"; = "block";
var imageURI = uri;
if (!imageURI || ( == "none")) {
document.getElementById('picture_msg').innerHTML = "Tap on picture to select image from gallery.";
// Verify server has been entered
server = document.getElementById('server').value;
server = 'http://domain_name/mobile_app/img_upload.php';
console.log("Server "+server);
if (server) {
// Specify transfer options
var options = new FileUploadOptions();
options.chunkedMode = false;

// Transfer picture to server
var ft = new FileTransfer();
ft.upload(imageURI, server, function(r) {
document.getElementById('picture_msg').innerHTML = "Upload successful: "+r.bytesSent+" bytes uploaded.";
img.src = uri;
img.width = 100;
img.height = 100;
function(error) {
document.getElementById('picture_msg').innerHTML = "Upload failed: Code = "+error.code;
}, options);
else {
document.getElementById('picture_msg').innerHTML = "Server Not Found";
catch(exce) {
function(e) {
console.log("Error getting picture: " + e);
document.getElementById('picture_msg').innerHTML = "No Image Found";
quality: 50,

And here is the img_upload.php code.

$new_image_name = "namethisimage.jpg";
move_uploaded_file($_FILES["file"]["tmp_name"], "mobile_app/".$new_image_name);

I tried this as well.

$dirname = "user_img/";
// If uploading file
if ($_FILES) {
// mkdir ($dirname, 0777, true);

I am getting upload successful message but when i check the data on server it is showing empty. No files are there.

Please advise what am i doing wrong here.



It seems like problem with php file. path in webserver is

my php file img_upload.php is under app folder.

I am not sure what to do now. I checked multiple options from google but this is not working.


Finally after 7 days i fixed the issue. Actually i was very stupid. You will laugh on me.

The url i had given was i just need to add www in the url. So, working URL is http://www/ It fixed the issue.

I hope someone else will get the help from it.