0

I am trying to receive some image data in php using $_POST if I am trying to post small string like "abc" I am getting the response but when I try to post huge data like 108 KB it's not showing the response might be I need to increase some limit but I don't have access in php.ini file.

is there any other way?

And I am posting the data from android so is there any string shorten encoding in android and decoding in php available. I already used base64 to get the image data.

My php code to echo the return.

<?php
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: PUT, GET, POST, DELETE, OPTIONS');
header('Access-Control-Allow-Headers: Content-Type');


if(isset($_POST['incidentDetails']))
{
    echo 'Responce from server:  ' . $_POST['incidentDetails'];
}
else
{
    echo 'Request without paramenter';  
}
?>

The url - http://bumba27.byethost16.com/incidentManagments/api/adding_incident_details.php

I need to post as parameter name incidentDetails- http://www.filedropper.com/log_2

enter image description here

Android Code

// Create a new HttpClient and Post Header
        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost("http://bumba27.byethost16.com/incidentManagments/api/adding_incident_details.php");

        try 
        {
            List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
            nameValuePairs.add(new BasicNameValuePair("incidentDetails", headerData));
            httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

            HttpResponse response = httpclient.execute(httppost);

            responseCode = response.getStatusLine().getStatusCode();
            responseBody = EntityUtils.toString(response.getEntity());
        } 
        catch (Throwable t ) 
        {
            Log.d("Error Time of Login",t+"");
        } 
Apul Gupta
  • 3,044
  • 3
  • 22
  • 30
A J
  • 4,542
  • 5
  • 50
  • 80
  • 1
    if you are dealing with image files why are you using $_POST instead of using $_POST use $_FILES – Vivek Singh Mar 21 '15 at 08:03
  • no it's is base64 converted image. Actually there will be many image and along with the image I need to pass other parameter also that why I need to pass as base64 – A J Mar 21 '15 at 08:19
  • 1
    Even if you have many images and many parameters there is no need to base64 encode images. – greenapps Mar 21 '15 at 08:39
  • 1
    `it's not showing the response` . No? Nothing? Where do you display the response? Why are you asking for string shortening code where base64 increases payload with 30℅ ? – greenapps Mar 21 '15 at 08:42
  • Updated my question with url and parameter – A J Mar 21 '15 at 08:48
  • 1
    We cannot see that you posted a base64 encoded image. Only a image url. We cannot see the response. You did not answer my questions. You did not tell why you want images to be base64 encoded. You did not tell you would post json. – greenapps Mar 21 '15 at 09:04
  • I am sending this from android device android android code is already ready from android it is posting base64 I can't modify that and yes I from android side I am getting all parameter as json. for that posted base64 image please download this file .http://www.filedropper.com/log_2 You can see full thing that I am trying to pass – A J Mar 21 '15 at 09:08
  • 1
    `I am getting all parameter as json. ` ??? You mean: i send all parameters including the images as json text? – greenapps Mar 21 '15 at 09:11
  • Yes I send all parameters including the images as json – A J Mar 21 '15 at 09:12
  • 1
    My god you should have stated that as first line in your post right away. You are just trying to send json text. Now you spilled our time. And still you did not answer my comment on `its not showing the response`. – greenapps Mar 21 '15 at 09:16
  • As per my php code you can see I put echo. so it should say 'Responce from server: bla bla bla but now I getting complete blank nothing is there but if I post "abc" instead of that json I am getting 'Responce from server: abc' That mean due to big json value I am facing some problem from php server side I think so .... any suggestion ... and am really sorry not to explain properly.. – A J Mar 21 '15 at 09:21
  • If you are getting nothing than it times out ? Is nothing/blank not even 'Response from server: ' ? Post your android code please. – greenapps Mar 21 '15 at 09:34
  • Why did you not state on the first line that you want to receive a big json text? Come to the point please. You dont have to talk about images and base64. – greenapps Mar 21 '15 at 09:40
  • not getting your point – A J Mar 21 '15 at 09:40

1 Answers1

1

Are you making sure you have enctype="multipart/form-data" in your form tag on the HTML form sending the image data?

<form name="someform" id="someform" enctype="multipart/form-data" method="post" action="somefile.php">

EDIT: According to the PHP.NET website, you have to do a process to save files - not just print out the $_POST array:

$name= $_FILES["myfile"]["name"];
$type= $_FILES["myfile"]["type"];
$size= $_FILES["myfile"]["size"];
$temp= $_FILES["myfile"]["temp_name"];
$error= $_FILES["myfile"]["error"];

if ($error > 0)
    die("Error uploading file! code $error.");
else
   {
    if($type=="image/png" || $size > 2000000)//condition for the file
    {
    die("Format  not allowed or file size too big!");
    }
    else
    {
     move_uploaded_file($temp, "uploaded/" .$name);
     echo "Upload complete!"; 
     }
}
NYCBilly
  • 870
  • 1
  • 8
  • 11
  • I am only getting result on application/x-www-form-urlencoded You can also try - http://bumba27.byethost16.com/incidentManagments/api/adding_incident_details.php Parameter- incidentDetails – A J Mar 21 '15 at 08:38
  • 1
    I just sent Desert.jpg (stock Windows background image) via a form using application/x-www-form-urlencoded - did you get anything? – NYCBilly Mar 21 '15 at 08:50
  • I am not saving any thing in data base primarily just doing echo the result – A J Mar 21 '15 at 08:52
  • You can use Advanced Rest Client to check the response I have updated my question also. – A J Mar 21 '15 at 08:55
  • I can't upload the image like this in that case I need to change the android code also. I need to post it as Base64 I have attached the url as well as parameter also.. Please if you don't mind can you check that.. – A J Mar 21 '15 at 08:57
  • Did you look at this SO Q&A?: http://stackoverflow.com/questions/3259967/sending-displaying-a-base64-encoded-image – NYCBilly Mar 21 '15 at 09:01
  • Yes @NYCBilly I am doing base64_encode from android side and sending to php server problem is php server can't receive it due to big parameter value. Check the parameter file I had added as .text in my question. – A J Mar 21 '15 at 09:06