Upload Screenshot to Webserver?

Hi, can’t figure it out.

Upload PNG, seems to work fine

function UploadPNG() 
{
    // 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/php script
    var w = WWW(screenShotURL, form);
    yield w;
     

    if (w.error != null)
       pass = true;
    else
       pass = false;
       
}

PHP

<?php 
if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/png"))  ($_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"; 
} 
?>

should my screenshot URL be relative to the webplayer or absolute?

I think I am getting the invalid file error because m php page is constantly like that (don’t know php all too well)

bump

Kilt - try being specific on what is going wrong. I did something similar about a year ago and had success. Maybe if you give the exact error, someone can help.

Gigi.

It is about as specific as I can get, I can get it to the script I think, because it does not pass any errors, then from there. I don’t know.

the upload loads it into php as a $_FILE correct? and it is “image/png”, I have an upload folder on the webserver, I am just stumped.

Won’t upload

bump