Reputation: 4632
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
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+"");
}
Upvotes: 0
Views: 6619
Reputation: 870
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!";
}
}
Upvotes: 1