Hey ,
i build a Unity Update for my game inside the Editor, but i have one problem with the WWW Uploader.
he uploaded only one file, but the second not.
using UnityEngine;
using UnityEditor;
using System;
using System.Collections;
using System.IO;
public class UpdateGameWindow: EditorWindow
{
void OnGUI()
{
....
..
.
if (GUILayout.Button("Upload - All", GUILayout.Width(150)))
{
WWWForm form = new WWWForm();
form.AddBinaryData("update[]", ReadFile(Application.dataPath + @"\GameUpdate\Network.sis"), "Network.sis");//<--- Upload AssetBundle File
form.AddBinaryData("update[]", ReadFile(Application.dataPath + @"\GameUpdate\de.sis"), "de.sis");//<--- Upload AssetBundle File
WWW request = new WWW("http://myadress/test.php",form);
while (!request.isDone)
{
SleepSecs(1); //<-- Doesn't work in Editor and Unity is freezing for a moment
}
Debug.Log(request.error);
Debug.Log(request.text); //<-- Answer from test.php (look down)
}
}
IEnumerator SleepSecs(float secs)
{
yield return new WaitForSeconds(secs);
}
public static byte[] ReadFile(string filePath)
{
byte[] buffer;
FileStream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read);
try
{
int length = (int)fileStream.Length;
buffer = new byte[length];
int count;
int sum = 0;
while ((count = fileStream.Read(buffer, sum, length - sum)) > 0)
sum += count; // sum is a buffer offset for next reading
}
finally
{
fileStream.Close();
}
return buffer;
}
}
And the php test.php
<?PHP
print_r($_FILES);
?>
Answer :
Array
(
[name] => Array
(
[0] => Network.sis
)
[type] => Array
(
[0] => sis
)
[tmp_name] => Array
(
[0] => /var/www/virtual/myadress/phptmp/phphsiWv8
)
[error] => Array
(
[0] => 0
)
[size] => Array
(
[0] => 1918
)
)
<< and here is my problem !!!
there is only one array.