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
1
Question by Ben 35 · May 17, 2011 at 04:03 PM · wwwwwwformfile-ioread

Write to online file with webplayer

I know that the WWW or WWWForm class should be used in conjunction with a server side script such as PHP, but I can not get it to work. I am basically doing this:

var www : WWW;
var form = new WWWForm();
form.AddField("frameCount", Time.frameCount.ToString());
www = WWW(url, form); //upload to script
yield www;

Where "url" is a PHP script in the cgi-bin folder on the server where the webplayer is. The PHP script is:

<?php
$filename = 'test.txt';
$Content = "Add this to the file\r\n";
$handle = fopen($filename, 'x+');
fwrite($handle, $Content);
fclose($handle);
?>

I know I am not using "frameCount", but I do not know of an alternative way to put WWW in POST mode. Anyway, this does not produce "test.txt" or write to "test.txt" if I create the file on the server. What am I doing wrong? I know I have access to the PHP script in Unity because I can display its contents in GUIText using the following:

var www : WWW = new WWW (url); var form = new WWWForm();

yield www; // Wait for download to complete

if (www.error != null) this.GetComponent(GUIText).text = www.error; else this.GetComponent(GUIText).text = www.text;

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Tommy · May 17, 2011 at 04:16 PM

If you'r trying to add what Unity sends to the server, maybe you shall do something like this in the PHP script.

<?php
$filename = 'test.txt';
$Content = $_POST['frameCount'];
$handle = fopen($filename,"w");
fwrite($handle, $Content);
fclose($handle);
?>

Note this will probably overwrite whatever's in there, i can add som code for you if you want to ADD the frameCount to the file instead.

Comment
Add comment · Show 10 · 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 Ben 35 · May 17, 2011 at 04:43 PM 0
Share

Thanks, but this still does not create a file. Also, shouldn't it be fopen($filename, "x+");? I tried fopen("test.txt","x+"); and it still doesn't work. Does it matter whether single or double quotes are used when passing things to a function? I have seen examples both ways. And your fwrite would write the word $Content, not the value, correct? Regardless, this does not create a file. Could it be a permissions thing? I can not see the permissions of the script on the server, but on my local machine it is "full control". Ben 0 secs ago

avatar image Tommy · May 17, 2011 at 04:53 PM 0
Share

It won't create a file since you put

$handle = fopen($filename.".txt","x+");

I don't know what the x+ does, but you'll have to use "w" to write to a file, and create a file. Try changing x+ to w. And yes, i belive you should remove the "" from $Content, my bad :-)

avatar image Tommy · May 17, 2011 at 04:58 PM 0
Share

Edited the code a bit, hope it'll to the trick!

avatar image Ben 35 · May 17, 2011 at 05:10 PM 0
Share

I tried your new code and it still does not work. No file is created. If I create test.txt, nothing is written to it. I think the script is probably correct... it must be something else.

avatar image Tommy · May 17, 2011 at 05:17 PM 0
Share

Does you webserver have permission to read/write to the folder? Are the script in the same folder as the textfile? Are you looking for it in the same folder? What webserver do you use? What OS are you using?

Show more comments

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

No one has followed this question yet.

Related Questions

Retrieving varibale values from a php script? 1 Answer

WWWform- works in UnityPlayer & REST service but not on android 1 Answer

wwwform send an array the right way! 0 Answers

Handle Blank Response From Web Server 0 Answers

Sending cookie to XML-RPC protocol 0 Answers


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