I am designing a app in phonegap. I send multiple base64 images to php webservice. Now i need to decode all those base64 images and save them into database.

I am hoping for the best solution. Thank you.

This is my code for assigning base64 values into a hidden input type.

```
for(i = 0; i< image.length;i++){
    $('#table_postad').append('<input type="hidden" value="'+image[i]+'"    name="ad_image'+i+'" class="ad_image"/>');
    imageArray.push(document.getElementsByClassName("ad_image")[i].value);
}

```

Following is the code to connect server:

```
var server =  'http://example.com/webServiceForProject/';
function sendDataToServer(){
alert("access");
var datas = $("#form_description").serialize();//form_description is id for form
console.log(datas);
$.ajax({
    type: 'POST',
    data: datas,
    url: server+'insert.php',
    success: function(data){
        alert(data);
    },
    error: function(){
        alert('There was an error adding your comment');
    }   
});

```

}

this is php code:

```
<?php
    define('UPLOAD_DIR', 'images/');
    $adPhotos = array();
    $i=0;
    while(isset($_POST["ad_image".$i])){
        array_push($adPhotos,($_POST["ad_image".$i]));
        $i++;
        echo($adPhotos[i]);
    }
    $j = 0;
    while(sizeof($adPhotos)){
    $adPhotos[$j]= str_replace('data:image/png;base64,', '', $adPhotos[$j]);
    $adPhotos[$j]= str_replace(' ', '+', $adPhotos[$j]);
    $file[$j] = UPLOAD_DIR . uniqid() . '.png';
    $success = file_put_contents($file[$j], $data[$j]);
        j++;
    }
    //insert code here.....

?>

```