I am trying to store data locally and retrieve local data via a WebGl application. It does not work via System IO for some security reasons (I have read). I have tried with WWW. It works without problems to write a local file via a php page/file that I call. In Unity editor it works to write and also read the local file using this code. But in WebGl only writing works. However, I can not read the file in webGL.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Networking;
using System.Text.RegularExpressions;
using UnityEditor;
public class Writetofile : MonoBehaviour
{
public Text Test;
private void OnGUI()
{
GUIStyle buttonStyle = new GUIStyle(GUI.skin.button);
buttonStyle.fontSize = 25;
if (GUI.Button(new Rect(10, 10, 450, 80), "Send Information To File", buttonStyle))
{
Test.text = "test";
StartCoroutine(sendTextToFile());
}
if (GUI.Button(new Rect(10, 100, 450, 80), "Send Information To File", buttonStyle))
{
StartCoroutine(getTextFromFile());
}
}
IEnumerator sendTextToFile()
{
bool successfull = true;
WWWForm form = new WWWForm();
form.AddField("name", "Joe Bloggs");
form.AddField("age", "32");
form.AddField("score", "125");
WWW www = new WWW("http://localhost:9000/fromunity.php", form);
yield return www;
if (www.error != null)
{
successfull = false;
}
else
{
Debug.Log(www.text);
successfull = true;
}
}
IEnumerator getTextFromFile()
{
bool successfull = true;
WWWForm form = new WWWForm();
WWW www = new WWW("http://localhost:9000/tounity.php", form);
yield return www;
if (www.error != null)
{
successfull = false;
}
else
{
Test.text = "" + www.text;
Debug.Log(www.text);
successfull = true;
}
}
}