Upload Screenshot VIA PHP or Perl

I have found this script in the unity scripting reference, and would like to know what i should have this .pl script as. I do not know python so if anyone could help that would be great.

// Grab a screen shot and upload it to a CGI script.
// The CGI script must be able to hande form uploads.

var screenShotURL= "http://www.my-server.com/cgi-bin/screenshot.pl";

// Take a screen shot immediately
function Start() {
    UploadPNG();
}

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("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);    
    else
        print("Finished Uploading Screenshot");    
}

The perl script should be any perl script that can handle a form input with an image (in .png format) as the form input data.

You may find this usefull:
How to Use a Form Data in Perl

but instead of having an html form send the data you are using the unity script.

BUMP.I need it with PHP not Perl, I need it to automatically handle it and work with unity

i know this is an older topic but i was wondering if anyone had an understanding of perl. I’m using the unity webplayer and have the code i need to save the image to a form, taken from Unity - Scripting API: WWWForm and modified for my usage.

The link post by softwizz is a little over my head, i guess i’m looking for a kind soul to give me a heads up on what’s what with perl in this case. Been looking through a few tutorial sites, but any other suggests is appreciated.

1 Like