Log in

View Full Version : file_get_contents('php://input')



hemi519
12-03-2010, 07:09 PM
Hi All,

I am getting request from a client to my php file. Iam unable to get the content he is sending to me. I am using file_get_contents('php://input') to get his data. but iam unable to do so can anyone help me plz.

I wrote like this to get the data

$incoming = file_get_contents('php://input')

when iam printing $incoming it is showing me

12-04 00:19:02.119: INFO/System.out(326): Response ... from=abc%40gmail.com&to=%22sbc%22+%3Casd519ssa%40gmail.com%3E%2C+&displayname=ssssss%40gmail.com&password=sdfsdfsdf&subject=Sdfsdf&message=Sdfsdfdsf&imagecontent

can i get the value individually from all these names(from,to,displayname,password,subject)

bluewalrus
12-03-2010, 08:02 PM
You could explode at each = I think


$values_are = explode ("=", $incoming);


to if it's correct



print_r($values_are);

djr33
12-03-2010, 09:08 PM
$tempvalues = explode('&',$in);
foreach($tempvalues as $value) {
$value = explode('=',$value);
$values[$value[0]] = $value[1];
}
print_r($values);

hemi519
12-06-2010, 04:44 AM
1)is thr any another way insetead of using file_get_contents('php://input') to get the values from client.

2)

In the below code i have a problem

$uploadBase = "/var/www/website/images/";
$uploadFilename = time() . ".jpg";
$uploadPath = $uploadBase . $uploadFilename;
$incomingData = file_get_contents('php://input');
$tempvalues = explode('&',$incomingData);
foreach($tempvalues as $value)
{
$value = explode('=',$value);
$values[$value[0]] = $value[1];
}
$from = $values["from"];
$to = $values["to"];
$display = $values["displayname"];
$password = $values["password"];
$image = $values["imagecontent"];
$fh = fopen($uploadPath, 'w') or die("Error opening file");
fwrite($fh, $image) or die("Error writing to file");
fclose($fh) or die("Error closing file");


iam getting request from client(he is sending strings and also image bytes) with this code iam able to get all the strings correctly, but in the $image = $values["imagecontent"]; iam unable to get the exact bytes he is sending. that is because bytes are something like this ($ddd@#$FDWS!DSEWE@#$@#@#@"@$@$@$@$$@$@EASDQW"ED#@$) These symbols are breaking(" " ") in the string and rest of the bytes are not taken as string. So iam unable to get the exact bytes into my $image. How can i get rid of this