Jump to content

  • Log In with Google      Sign In   
  • Create Account

Charabis

Member Since 08 Apr 2006
Offline Last Active Apr 28 2013 04:31 PM

Posts I've Made

In Topic: Javascript Equivalent of C# MD5

06 February 2012 - 01:59 PM

I had noticed that. Part of why I was hoping for something simpler like just getting the SSL now instead of waiting. The code will just have to be changed to use it then, so why not do it right the first time?

Unfortunately it's a matter of determining how C# gets its results and finding the matching Javascript version that's out there. Something tells me this is not a common problem :P

In Topic: Loading PNG In PHP And Returning It To C#

10 January 2012 - 09:49 AM

Okay, it turns out the problem wasn't in any of the code I posted. StartSending uses Unity's WWW object to communicate with the server. I was still using the version I was using to pass XML around (WWW.text), which is not advised for binary data. That's what "WWW.bytes" is for >.<

In Topic: Loading PNG In PHP And Returning It To C#

10 January 2012 - 08:52 AM

Back to the problem early :) The size of the file is 4183 as reported by "filesize()" in PHP. Using Deprecated's suggestion of "print(readfile($data_location . "/" . $file));" returns a string to the C# script that's only 4040. Using my original method of "$arr[] = file_get_contents($data_location . "/" . $file);" and echoing element 0 (the one element in this test case), yields a string of size 4036. Can anyone explain why both of these are shorter than the number of bytes in the original file? I hadn't thought it would be so tricky to get a byte array into PHP and return it to the C# script that calls it, but that certainly seems to be the case.

Calling code and reporting result
   WWWForm form = new WWWForm();
   form.AddField("merchant", accountID);
   form.AddField("test", testMode);
  
   string result = sendData.StartSending(form, prepend + "get_images.php");
  
   Debug.Log(result.Length);

PHP Code
<?php
if(filter_has_var(INPUT_POST, "merchant") && filter_has_var(INPUT_POST, "test"))
{
$merchant = filter_input(INPUT_POST, "merchant", FILTER_SANITIZE_STRING);
$test = filter_input(INPUT_POST, "test", FILTER_SANITIZE_STRING);
}
else
{
die ("DataMissing");
}
$data_location = $_SERVER['DOCUMENT_ROOT'] . "/" . $merchant;
$arr = array();
if (is_dir($data_location))
{
    $dir = opendir($data_location) or die("Couldn't access directory!");
    while (($file = readdir($dir)) !== false)
    {
	 if($file != "." && $file != "..")
	 {
	  //print(readfile($data_location . "/" . $file));
	  $arr[] = file_get_contents($data_location . "/" . $file);
	 }
    }
   
echo $arr[0];
closedir();
}
else
{
// Need to create it
mkdir($data_location, 0700) or die("Couldn't create " . $data_location);
echo "Empty";
}
?>

In Topic: Loading PNG In PHP And Returning It To C#

09 January 2012 - 06:20 PM

Ah. That's much shorter than trying to echo it, and gets the same results. Unfortunately, the results still don't seem to want to load as an image. Then too, there's the matter of returning it as an array of images regardless. At least this gets a good start on tomorrow. Thanks for the assist, Deprecated.

In Topic: Loading PNG In PHP And Returning It To C#

09 January 2012 - 05:53 PM

Okay, seems there's a gotcha I wasn't aware of. I haven't confirmed 100% that the above works, but I was able to confirm that part of the code results in a bit of an oddity.

while (($file = readdir($dir)) !== false)
{
$arr[] = file_get_contents($file);
}


Detects 3 files even though only one is in the folder. The other two filenames it picks up are "." and "..". Wrapping the the line to load the file inside

if($file != "." && $file != "..")


returns something that looks like it might be what I wanted. The size of the byte[] is about what I expected :)

PARTNERS