- Home /
Sending binary data not working with apache + php now
here's example form:
WWWForm form = new WWWForm();
form.AddField("foo","bar");
form.AddField("baz","bad");
//image_data is the screenshot in png format
form.AddBinaryData("image", image_data ) ;
and i'm getting this jumbled array in $_POST
data:
Array
(
[
--j9WOVWjhzifMBMOxK4Gcn4HcAYobnKmq3WyCjNiJ
Content-Type:_text/plain;_charset] => "utf-8"
Content-disposition: form-data; name="foo"
bar
--j9WOVWjhzifMBMOxK4Gcn4HcAYobnKmq3WyCjNiJ
Content-Type: text/plain; charset="utf-8"
Content-disposition: form-data; name="baz"
bad
009480823dc102f6f612ffb2c0e5fb79647c60a950c0c84c430f43c72869c0aa
--j9WOVWjhzifMBMOxK4Gcn4HcAYobnKmq3WyCjNiJ
Content-Type: image/png
Content-disposition: form-data; name="map_image"; filename="map_image.png"
\x89PNG
\x1a\n
any ideas?
I am getting the same output, did you have any luck fixing this?
What's jumbled about that? Looks like 3 sections, each with the expected data to me. The only gotcha I see is the PNG section seems to be cut short, possibly because it contains a NULL character which makes the PHP array dumping code think it's got to the end of the data. Well, I guess the line after bad
is actually part of the PNG file, so maybe that's odd.
In my case, this is the php code that I have for uploading the file. It seems that it doesn't get past the if ( isset($_POST['action')) line:
if ($_POST)
{
if (isset ($_POST['action']))
{
if ($_POST['action'] == 'upload')
{
// backwards compatibility with old servers
if (!isset($_FILES) && isset($HTTP_POST_FILES))
{
$_FILES = $HTTP_POST_FILES;
}
if ($_FILES['file']['error'] == UPLOAD_ERR_O$$anonymous$$)
{
if ($_FILES['file']['name'] != "")
{
if ($_FILES['file']['type'] == 'text/json')
{
$uploadfile = dirname(__FILE__) . '/' . $_FILES['file']['name'];
move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile);
}
}
}
}
}
}
The same php (and the same c# code) work fine on a non-apache server that I have tried.
Sounds like you need an Apache server q&a site.
Answer by the1plummie · Jun 02, 2013 at 01:24 PM
actually upgrading to unity 4.1.3 seem to make the issue go away. and make sure you have the right header for content type. :) (actually not specifying header works as well)
Ahh I cannot upgrade to Unity 4.0 :( I want the game to be published with 3.5 as this is what I have purchased, can't really afford to buy a new license.
Are there no other workarounds? I am sure I have the right header. I also tried not specifying a header, I got the same result basically.
sorry i've always being on unity 4.0+ so not sure about older versions. what content type header are you using btw?
Answer by mgeorgoulopoulos · Jun 02, 2013 at 09:52 PM
Content type is text/json. I have tried everything else, even not specifying a header hashtable at all, I still cannot get this to work.
The thing is it works on the non-apache server, so it has to be something server related. I tried speaking to the hosting support with no luck :(
hmm, if the data you needed to send is json encoded string, you don't need to send it using binary format. why can't you just put that in WWWForm post data? if it's small enough, you might be able to fit it in url itself.
How would I do that? Don't I still need to upload it somehow? It cannot fit in the url as it's a quite long file (or at least, it will become long soon).
Your answer

Follow this Question
Related Questions
Use the data received from WWW in UI 1 Answer
WWW Class is acting up 1 Answer
Cloud recognition in Vuforia 0 Answers
Is there a way to fix uploadprogress on mobile? 1 Answer
Post image to facebook wall 0 Answers