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