uploading screenshot to server

Hi guys

I am trying to upload a screenshot of my scene at the server using the WWW class. You can find here http://www.ionio.gr/~av200420/screen/screen.html my simple application. While clicking the cube an alert message says that the screenshot uploaded. I read that i should have a crossdomain.xml file, so, i uploaded here http://www.ionio.gr/~av200420/crossdomain.xml. In unity now I assign the screenshot url var screenShotURL= “http://www.ionio.gr/~av200420”; My problem is that unity says that everything is OK but i can find somewhere the screenshot to my server… Is there any problem with the assigned values or routs?

Thanks!

Your upload url doesn’t look like there’s anything on your server that can receive the upload? Do you have a serverside php script that saves the upload? It seems you forget that…

To take a screenshot and upload it there’s an example in the Unity docs.

Here’s a similar question where you can see how the serverside script can look like:

Unityscript:

var screenShotURL= "http://localhost:8888/upload_file.php";

function Start(){ 
	//print(Application.srcPath); 
}

function OnMouseDown() { 

	// 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");
	}
}

PHP:

<?php 
	if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/pjpeg")) && ($_FILES["file"]["size"] < 20000000000)) { if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . "
	"; } else { echo "Upload: " . $_FILES["file"]["name"] . "
	"; echo "Type: " . $_FILES["file"]["type"] . "
	"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb
	"; echo "Temp file: " . $_FILES["file"]["tmp_name"] . "
	";

	if (file_exists("upload/" . $_FILES["file"]["name"]))
	  {
	  echo $_FILES["file"]["name"] . " already exists. ";
	  }
	else
	  {
	  move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]);
	  echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
	  }
	}
	} else { echo "Invalid file"; } 
?>

I don’t know why but it doesn’t work yet. I am using this javascript

var screenShotURL= "http://localhost:8888/upload_file.php";

//var screenShotURL= “http://195.130.124.68/cgi-bin/screenshot.pl”;

function Start(){
//print(Application.srcPath);
}

function OnMouseDown() {
// 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("fileUpload", 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");
}

}

and this php script

`

<?php if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/pjpeg")) && ($_FILES["file"]["size"] < 20000000000)) { if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . " "; } else { echo "Upload: " . $_FILES["file"]["name"] . " "; echo "Type: " . $_FILES["file"]["type"] . " "; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb "; echo "Temp file: " . $_FILES["file"]["tmp_name"] . " "; if (file_exists("upload/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]); echo "Stored in: " . "upload/" . $_FILES["file"]["name"]; } } } else { echo "Invalid file"; } ?>

`

The program sais that the image uploaded… but there is no image inside the upload folder. Is there any wrong with the scripts? Do I want any other script in order to upload the screenshot???

Thanks again!