- Home /
Upload image or file into server using 3D C#
I want to upload an image from 3D but i am getting elow error:
Error during upload: 405 Method Not Allowed UnityEngine.Debug:Log(Object)
Below is code snippet C# script:
private string m_LocalFileName = "C:/Content/images/annual.png"; private string m_URL = "http://52.81.27.216/Unity/upload.php"; // Use this for initialization IEnumerator UploadFileCo(string localFileName, string uploadURL) { WWW localFile = new WWW("file:///" + localFileName); yield return localFile; if (localFile.error == null) Debug.Log("Loaded file successfully"); else { Debug.Log("Open file error: "+localFile.error); yield break; // stop the coroutine here }
WWWForm postForm = new WWWForm();
// version 1
//postForm.AddBinaryData("theFile",localFile.bytes);
// version 2
postForm.AddBinaryData("file",localFile.bytes,"annual.png","image/png");
WWW upload = new WWW(uploadURL,postForm);
yield return upload;
if (upload.error == null)
Debug.Log("upload done :" + upload.text);
else
Debug.Log("Error during upload: " + upload.error);
}
void UploadFile(string localFileName, string uploadURL)
{
StartCoroutine(UploadFileCo(localFileName, uploadURL));
}
void OnGUI()
{
GUILayout.BeginArea(new Rect(0,0,Screen.width,Screen.height));
m_LocalFileName = GUILayout.TextField(m_LocalFileName);
m_URL = GUILayout.TextField(m_URL);
if (GUILayout.Button("Upload"))
{
UploadFile(m_LocalFileName,m_URL);
}
GUILayout.EndArea();
}
php code snippet:
$f3->route('POST /test', function() if(isset($_FILE['file']; { echo "Success!"; } else { echo "Failed!"; } }
Did you try $_FILES['file'] seems like a typo in PHP code
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
IN-GAME Menu Items 0 Answers
Advice for deploying to iOS from cloud build 0 Answers
Unity freeze at custom parameters for 'Unwrapping.GenerateSecondaryUVSet()' 1 Answer