Results 1 to 4 of 4

Thread: file_get_contents('php://input')

  1. #1
    Join Date
    Nov 2010
    Posts
    115
    Thanks
    27
    Thanked 0 Times in 0 Posts

    Default file_get_contents('php://input')

    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&imageconten t

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

  2. #2
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    You could explode at each = I think

    PHP Code:
    $values_are explode ("="$incoming); 
    to if it's correct

    PHP Code:
    print_r($values_are); 
    Corrections to my coding/thoughts welcome.

  3. The Following User Says Thank You to bluewalrus For This Useful Post:

    hemi519 (12-04-2010)

  4. #3
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    PHP Code:
    $tempvalues explode('&',$in);
    foreach(
    $tempvalues as $value) {
       
    $value explode('=',$value);
       
    $values[$value[0]] = $value[1];
    }
    print_r($values); 
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  5. The Following User Says Thank You to djr33 For This Useful Post:

    hemi519 (12-04-2010)

  6. #4
    Join Date
    Nov 2010
    Posts
    115
    Thanks
    27
    Thanked 0 Times in 0 Posts

    Default

    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
    Last edited by hemi519; 12-06-2010 at 04:57 AM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •