Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
0
Question by anirudha_vfx · Oct 22, 2013 at 01:40 PM · triggerserversavefilescreenshot

Screenshot script not uploading PNG to server when used with key trigger

Hello. I have tried using the script provided in the Unity documentation for uploading the screenshot to the server. It seems to work and upload the PNG to the server. I modified the script to run on a "Jump" button trigger. But it does not seem to work. The "Jump" button is not used by any other script. Here is the script #pragma strict

 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 script
 var w = WWW("www.mydomain-s.com/unity/screenshot4/screenshot4.php", 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 Update () {
 
         if(Input.GetButtonUp("Jump")){
             UploadPNG();
         }
     }
 


And here is the php script

     <?php
     if ((($_FILES["file"]["type"] == "image/png") || ($_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 web directory "Upload" has the write permissions set.

I'm stuck at it since hours. Would really appreciate the help.

Comment
Add comment · Show 4
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 ArkaneX · Oct 22, 2013 at 02:04 PM 0
Share

Have you checked if your UploadPNG script is called? Did you modify anything inside the UploadPNG function or in your PHP script after you successfully tested it?

avatar image anirudha_vfx · Oct 22, 2013 at 06:29 PM 0
Share

The UploadPNG() is unchanged. When the function is called from Start() without any trigger, the screenshot gets uploaded. But when a trigger is implemented in the Update() it is not working. I have tested the script with debug, and the console does gives the "Finished Uploading Screenshot" message. But when tested on server, nothing happens.

avatar image ArkaneX · Oct 22, 2013 at 08:14 PM 0
Share

Strange indeed. Are you able to track if the request reached server at all? You can also take a look at the request in your browser - does it contain texture data? If not, then please check bytes.Length after encoding to PNG.

avatar image DeveshPandey · Nov 01, 2014 at 04:02 PM 0
Share

you can use this great plugin http://u3d.as/9Ee

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by anirudha_vfx · Oct 28, 2013 at 05:30 AM

Its solved. You need to add full URL with "http" in the www function.

Thanks ArkaneX. Appreciate your time.

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

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

16 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 avatar image avatar image avatar image avatar image avatar image

Related Questions

Save and share from Web Player 1 Answer

how can i take a screenshot (by UiButton) and save it in CameraRoll (Gallery in iOS)? 0 Answers

Server RPC 1 Answer

[Solved] Take a Screenshot from game and use it immediately in UI 1 Answer

from bool array to binary file? 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