Uploading multiple images in webservice using PHP

deepak

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 file upload is given below.

$data = $_REQUEST;
if($data["prop_images"]){       
            $filename = md5(time()).'.jpg';
            $base=$data["prop_images"];
            $binary = base64_decode($base);         
            $pathtoupload = JPATH_ADMINISTRATOR . '/components/com_clinchproperties/galupload/';
            //header('Content-Type: bitmap; charset=utf-8');  // binary, utf-8 bytes
            $actual_image_name = time().".jpg";
            $image = $filename;
            $file = fopen($pathtoupload.$filename,  'wb');
            fwrite($file, $binary);
            fclose($file);
        }

I need code to upload n number of images at same time. Can any one help me with it? Thanks in advance.

Ravi Dhoriya ツ

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

HttpClient httpClient = new DefaultHttpClient();

HttpPost postRequest = new HttpPost("http://webserver.com/path/to/webservice.php");

MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);

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

//execute request.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Multiple images rename & uploading in PHP

From Dev

Multiple images rename & uploading in PHP

From Dev

Uploading Multiple Images using CarrierWave

From Dev

PHP: Uploading multiple images to imgur at once

From Dev

PHP: Uploading multiple images at the same time

From Dev

Uploading multiple images using SRWebClient in Swift

From Dev

Uploading images to mysql using php form

From Dev

Uploading multiple images with volley?

From Dev

Uploading multiple images in codeigniter?

From Dev

Uploading multiple images with paperclip?

From Dev

Uploading multiple images with Django

From Dev

Uploading multiple images in codeigniter?

From Dev

Django multiple images not uploading

From Dev

Uploading multiple images one to each row PHP and Mysqli db

From Dev

Uploading multiple images on twitter using Ruby on Rails Twitter Gem

From Dev

Error being displayed while uploading images using php to sql database

From Dev

All images not uploading in multiple images upload

From Dev

Wont uploading bigger images PHP

From Dev

PHP: Images file is not uploading on the server?

From Dev

Uploading images using Servlet 3.0

From Dev

Uploading images using Servlet 3.0

From Dev

Uploading Images in laravel using Intervention

From Dev

PHP foreach($images as $image) not uploading images

From Dev

Uploading multiple files in PHP using HTML Form or cURL

From Dev

Uploading multiple files in PHP using HTML Form or cURL

From Dev

JSON webservice using multiple databases

From Dev

Uploading multiple images from Share Extension

From Dev

Uploading multiple images with other parameters in Swift

From Dev

Django REST: Uploading and serializing multiple images

Related Related

HotTag

Archive