- Home /
Unity - JavaScript, it takes screen shot but doesn't post(form) to server. it works fine with pc (web cam) but not on android device. is it because of resolution????
The javascript code is as followes...
pragma strict
var screenShotURL= "http://localhost/upload_file.php";
function Start(){ //print(Application.srcPath); }
function Update () { //Upload(); }
function OnGUI(){
if (GUI.Button(Rect(Screen.width/2,64,256,64),"Save"))
Upload();
}
public function Upload() { // We should only read the screen after all rendering is complete yield WaitForEndOfFrame();
// Create a texture the size of the screen, RGB24 format var width = Screen.width; var height = Screen.height; var tex = new Texture2D( width, height, TextureFormat.RGB24, false );
// Read screen contents into the texture tex.ReadPixels( Rect(0, 0, width, height), 0, 0 ); tex.Apply();
// Encode texture into PNG var bytes = tex.EncodeToPNG(); Destroy( tex );
// Create a Web Form var form = new WWWForm(); form.AddField("frameCount", Time.frameCount.ToString()); form.AddBinaryData("file", bytes, "screenShot.png", "image/png");
// Upload to a cgi script var w = WWW(screenShotURL, form); yield w; if (w.error != null){ print(w.error); Application.ExternalCall( "debug", w.error); //print(screenShotURL); } else{ print("Finished Uploading Screenshot"); //print(screenShotURL); Application.ExternalCall( "debug", "Finished Uploading Screenshot"); } }
//reference : another unity answers-missed the link
//server script : file_upload.php (http://localhost/file_upload.php)
i had observed that, for image size less than 2mb it easily uploads. i am unable to solve this. please help me. i just want the screen shot to be post to server.
Your answer
Follow this Question
Related Questions
how to pass AJAX into php 1 Answer
How to post images to mysql using unity webrequest? 0 Answers
Screenshot to variable 1 Answer
Webplayer run in php 0 Answers