Skip to content Skip to sidebar Skip to footer

Uploading Multiple Images In Webservice Using Php

I am new to webservice using PHP for Android device. I need to work on multiple image upload concept. Please suggest. I have implemented single upload concept the code for single f

Solution 1:

You have to pass array of files. As you mentioned in comment, you are sending file data in base64 format, try following code for PHP.

PHP

  $data = $_REQUEST;
  if($data["prop_images"]){ 
    foreach($data["prop_images"] as $img){ //array of images. So loop for every images
        $filename = md5(time()).'.jpg';
        $base=$img;
        $binary = base64_decode($base);         
        $pathtoupload = JPATH_ADMINISTRATOR . '/components/com_clinchproperties/galupload/';
        $actual_image_name = time().".jpg";
        $image = $filename;
        $file = fopen($pathtoupload.$filename,  'wb');
        fwrite($file, $binary);
        fclose($file);
    }
  }

In android code, make sure to add [] in parameter name while making POST request. That parameter should be prop_images[] as per example I given above.

I'm not an Android developer, but I can post code from our Android developer.

Android

HttpClienthttpClient=newDefaultHttpClient();

HttpPostpostRequest=newHttpPost("http://webserver.com/path/to/webservice.php");

MultipartEntityreqEntity=newMultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);

for (inti=0; i < number_of_images; i++) {
    //convert your images to base64 and store in base64ImageData.
    reqEntity.addPart("prop_images[]", base64ImageData);   //adding parameter
}

//execute request.

Solution 2:

This will help you to check your web service

<formmethod="post"enctype="multipart/form-data"action="audioupload.php"><inputtype="file"name="file1"multiple><inputtype="submit"value="OK"></form>

audio.php
 <?php  
   move_uploaded_file($_FILES["file1"]["tmp_name"],"audio/".$_FILES["file1"]["name"]);   
  $url = "audio/".$_FILES["file1"]["name"];
  ?>

likewise developer can call this service n times.

Post a Comment for "Uploading Multiple Images In Webservice Using Php"