php code to receive image from cellphone

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • drumgor
    New Member
    • Apr 2010
    • 3

    php code to receive image from cellphone

    The cellphone uses the following C# code to send the image to picinput.php

    Code:
                  string baseUrl = "http://www.somwhere.com/picinput.php?picfile=" + fileName;
                    httpWebRequest = (HttpWebRequest)WebRequest.Create(baseUrl);
                    httpWebRequest.Timeout = 20000;
                    httpWebRequest.Method = "POST";                
                    httpWebRequest.ContentType = "application/x-www-form-urlencoded";
                    httpWebRequest.ContentLength = imageData.Length;
    
                    using (Stream oStream = httpWebRequest.GetRequestStream())
                    {
                        oStream.Write(imageData, 0, imageData.Length);
                        oStream.Close();
                    }
    What is the most efficient php code to receive this image and write it to a file on the web server?
    Last edited by Atli; Apr 1 '10, 04:41 AM. Reason: Added [code] tags.
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hey.

    I'm not sure the request that code creates is valid. A HTTP request that includes binary data is typically of the type "multipart/form-data", not "applicatio n/x-www-form-urlencoded".

    To quote the HTML4.1 specs:
    The content type "applicatio n/x-www-form-urlencoded" is inefficient for sending large quantities of binary data or text containing non-ASCII characters. The content type "multipart/form-data" should be used for submitting forms that contain files, non-ASCII data, and binary data.
    See more details at www.w3.org.

    When it receives a proper request, PHP simply puts files in the $_FILES array so that you can easily access them in your code.
    (See Handling file uploads in the manual.)

    Comment

    • drumgor
      New Member
      • Apr 2010
      • 3

      #3
      Thank you for that. As I am not writing the C# part of this, I have sent your comments to the person who is.

      My confusion arises in not knowing if I should be using $_POST, $_REQUEST, imagecreatefrom file, file_get_conten ts, HttpResponse::G etRequestBody or Http::GetREques tBodyStream or something else on the PHP side to capture the incomming data in a form that I can then write it as a file to a folder.

      Comment

      • drumgor
        New Member
        • Apr 2010
        • 3

        #4
        Sorry, I should read all your message.

        if($_FILES['image']['name']) { etc.

        What syntax do I use to get the incomming file into $_FILES?

        Comment

        • Atli
          Recognized Expert Expert
          • Nov 2006
          • 5062

          #5
          Originally posted by drumgor
          What syntax do I use to get the incomming file into $_FILES?
          None. PHP does that automatically. Any file sent as a part of a valid "multipart/form-data" request will be automatically added to the $_FILES array, where you can access them.

          For other types of requests, all fields sent in the body of a "applicatio n/x-www-form-urlencoded" POST request are added to the $_POST array, and all key-value pairs sent via the URL's query string are added to the $_GET array.

          Comment

          Working...