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 SevenUnearth · Aug 01, 2013 at 08:06 PM · webplayerfileframeupload

How to upload a local file via the web player?

I have a problem using the Iframe while I try to upload a file. The problem occurred in the ShowFile JavaScript function. I am able to call alert(blabla); but nothing else works. So I can upload the file but can't send a message to unity to say what it is.

Here's what I got for now:

An IFrame in my html page.

 <iframe id="myFrame"></iframe>

two functions in an external javascript

 function UploadFile()
 {
     var $frame = $('#myFrame');
        $frame.attr('src','../inc/upload.html');
        $frame.css('top',($('#unityPlayer').innerWidth()/2)-($frame.width()/2)-50);
     $frame.css('left',($(window).innerWidth()/2)-($frame.width()/2));
        $frame.show();
 }

 function ShowFile(path)
 {
     alert(blabla); <---- this works but anything that follow doesn't
     $('#myFrame').hide();
     u.getUnity().SendMessage("Uploader", "ShowImage", path);
 }

upload.html looks like this

 <!DOCTYPE html>
 <html>
     <body>
         <form action="fileUpload.php" method="post"
         enctype="multipart/form-data">
         <label for="file">Filename:</label>
         <input type="file" name="file" id="file">  

         <input type="submit" name="submit" value="Submit">
         </form>
     </body>
 </html>

and it calls fileUpload.php which looks like this

     <?php
         if ($_FILES["file"]["error"] > 0)
         {
             echo "Error: " . $_FILES["file"]["error"] . "  
 ";
         }
         else
         {
             move_uploaded_file($_FILES["file"]["tmp_name"], "FileUploaded/" . $_FILES["file"]["name"]);
             $path = "inc/FileUploaded/" . $_FILES["file"]["name"];
             echo '<script>ShowFile("'.$path.'");</script>';
         }
     ?>

Finally I have an object in unity named Uploader with a script that contains this code:

 public class uploader : MonoBehaviour {
     
     bool showImage = false;
     string path = "";
     
     void OnGUI()
     {
         if(GUI.Button(new Rect(100,300,100,40), "Upload"))
         {
             Application.ExternalCall("UploadFile");
         }
         
         if(showImage)
         {
             GUI.Label(new Rect(10,400,200,30), "blablabla");
         }
     }
     
     public void ShowImage(string path)
     {
         showImage = true;
         this.path = path;
     }
     
 }

Everything is on a local server and if I call u.getUnity().SendMessage("Uploader", "ShowImage", path); from uploadFile, it is actually called.

If anyone got an idea why the lines are not called, please let me know. Thanx!

Comment
Add comment · Show 1
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 Jamora · Aug 01, 2013 at 08:32 PM 0
Share

As per my understanding, the web player has zero access to the hard drive. I think what you're trying to do is impossible. I may be wrong.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Seizure · Aug 01, 2013 at 08:49 PM

It is very possible, the webplayer will talk with your server that can hold on to your files for you, this is very useful to keep file size down and only load files when needed. As to what is wrong I do not particularly see anything, I use C# and I always use coroutines and use a yield return w; (basically wait until the form has come back competely before continuing)

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 SevenUnearth · Aug 01, 2013 at 09:00 PM 0
Share

The problem is that I can't reach The IFrame neither the web player after the operation with the php file, but it is strange that I can reach the javascript which is in the same page in reality(via external javascript).

I can't seem to find a way using the coroutine and yield stuff for a file upload.

Thx for your answer.

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

Webplayer Log output missing stacktrace. 1 Answer

A node in a childnode? 1 Answer

How to Browse a photo or Open to gallery 3 Answers

Loading External Files for Web Deployment 1 Answer

Creating a save.xml file and a folder to stash it in 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