Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by chmo · Jun 17, 2011 at 11:35 AM · screenshotwwwform

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!

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image DeveshPandey · Oct 22, 2014 at 08:10 AM 0
Share

Hi Guys,

You can use this plugin Easy Downloader and Uploader

avatar image Herioke · Jan 22, 2015 at 07:23 AM 0
Share

so, did you guys made it work? i tried using the sample codes here and it did not work for me, i keep getting the "Finished Uploading Screenshot" but there is no screenshot on my server

avatar image Herioke · Jan 23, 2015 at 08:33 PM 0
Share

I used the same cod and i get the upload complet message, but there is no img on my server, can anyone help me?

3 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by Bunny83 · Jun 18, 2011 at 03:23 AM

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:
http://answers.unity3d.com/questions/48686/uploading-photo-and-video-on-a-web-server.html

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
2

Answer by miketucker · Jan 10, 2012 at 03:14 PM

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"; } 
 ?>
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Aestial · May 01, 2013 at 09:42 PM 0
Share

I spotted a little error here. You're uploading a .png file, but in php code the first condition is only for .gif, .jpeg and .pjpeg. you need to add ($_FILES["file"]["type"] == "image/png") to the first if statement.

avatar image
0

Answer by chmo · Jun 19, 2011 at 01:33 AM

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

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!

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Flubber · Aug 02, 2011 at 02:45 PM 0
Share

Hi there did you work this out in the end? We are looking at trying to upload pictures into a web player app built in Unity too.

avatar image miketucker · Jan 10, 2012 at 03:11 PM 1
Share

the above is correct but simply fix the name of the file being uploaded. Currently you have:

form.AddBinaryData("fileUpload", bytes, "screenShot.png", "image/png");

change 'fileUpload' to 'file'

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

11 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Screenshot in WebGL 0 Answers

Application.CaptureScreenshot vs ReadPixels EncodeToPNG 1 Answer

Unity editor sending screenshot to my bucket but Android build not sending screenshot. 0 Answers

Sending e-mails with attachments from webplayer 1 Answer

Save to a separate system folder 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges