Search Unity

  1. If you have experience with import & exporting custom (.unitypackage) packages, please help complete a survey (open until May 15, 2024).
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice

WWW, WWWForm, AddBinary, and PHP

Discussion in 'Scripting' started by abarrett86, Dec 2, 2009.

  1. abarrett86

    abarrett86

    Joined:
    Sep 9, 2009
    Posts:
    6
    I am trying to take a serialized object (byte[]), send it to a PHP script, which will store it in a MySQL table.

    I also want to reverse the process to retrieve the byte[] back from the PHP script.

    I have tried using the AddBinary function of WWWForm, but am unable to retrieve the data on the PHP end.

    I can see that it is being sent as some level because I
    print_r($GLOBALS); and see the name that I pass in as well as the size of the binary data and a few other stats.

    My question is how do I send that data from Unity (C#) to PHP and access the binary data in order to write to a database.

    Any help would be greatly appreciated.
     
  2. MatthewW

    MatthewW

    Joined:
    Nov 30, 2006
    Posts:
    1,356
  3. abarrett86

    abarrett86

    Joined:
    Sep 9, 2009
    Posts:
    6
    Thanks, that got me a little farther. Now when i get the byte array back, it is the same length as the one sent to the server, so that seems good.

    However, when trying to deserialize the byte[] received, I get the error:

    SerializationException: Unexpected binary element: 0

    I am taking the byte[], building a memory stream with it, and using BinaryFormatter.Deserialize the memory stream

    I can't seem to find anywhere that anyone has had a similar problem.

    If anyone else has run into a problem or something similar, I appreciate any suggestions.