Howdy, y’all! I was doing something today and seem to be having trouble simply uploading a WWWForm with post info. It’s been pretty frustrating and I can’t figure out why ha ha. The goal is to send a string from Unity to a PHP file, and that PHP file writes the string to a file called “newFile.txt”
This is happening in Unity:
IEnumerator UploadMetrics(string inMetrics) {
WWWForm form = new WWWForm();
form.AddField("action", "telemetry");
Debug.Log (inMetrics);
form.AddField("metric", inMetrics);
//uploadUrl is a string like "http://mywebsite.com/upload.php"
WWW w = new WWW(uploadUrl,form);
yield return w;
if (w.error != null) {
Debug.Log(w.error);
} else {
Debug.Log ("Successful Upload!");
}
}
While this is happening in PHP:
<?php
if ($_POST)
{
if ( isset ($_POST['action']) )
{
if($_POST['action'] === "telemetry")
{
$thetext = $_POST['metric'];
$myfile = fopen("newfile.txt", "w") or die("Unable to open file!");
fwrite($myfile, $thetext);
fclose($myfile);
}
}
}
?>
I’ve done similar stuff a million times before, generally with interacting with databases via SQL, but for some reason I’m just not seeing what I’m doing wrong. Any ideas?
Thanks so much!