PHP text writing issues.

Hey,

trying to get php to work for me(still), and it doesn't seem to want to do it. i found this,

http://www.experts-exchange.com/Web/WebDevSoftware/Flash/Q_20932516.html?query=PHP%2C+text+writing%2C+fwrite&topics=116

and pasted the suggestion in just to see if i could get something to pop out for me. when i click the button, all that happens is that a new browser window pops open with the code in it, no text file happens. obviously what i would like to have happen is NO browser window pop open, and a text file get born from the process, or overwritten.

thanks.
AlexSilvermanAsked:
Who is Participating?
 
negatyveCommented:
Oh, if you're planning to save a file on the client machine, you should think about using SharedObject..
0
 
AlexSilvermanAuthor Commented:
Okay, so i just found a thing saying the PHP won't run locally... is there a way to write out a txt file locally?
0
 
negatyveCommented:
The php file is ok, what you need is:


myLoadVars = new LoadVars();
myLoadVars.variableOne = "This is the contents of the first variable";
myLoadVars.variableTwo = "This is the contents of the second variable";
myLoadVars.sendAndLoad("textfileMaker.php", myLoadVars, "POST");


notice "sendAndLoad" instead of "send".

It works if:

- server supports php
- you have write permission on that folder

If you are testing it locally, you should use:

myLoadVars = new LoadVars();
myLoadVars.variableOne = "This is the contents of the first variable";
myLoadVars.variableTwo = "This is the contents of the second variable";
myLoadVars.sendAndLoad("http://localhost/foldername/textfileMaker.php", myLoadVars, "POST");
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
negatyveCommented:
ehehe, I was answering..
0
 
AlexSilvermanAuthor Commented:
just was looking into them.

how do you use a shared object to write variables to?
0
 
negatyveCommented:
// gets the saved cookie: if it's missing, creates it
var so = SharedObject.getLocal("cookie_name");
// if you saved "your_property" in the inner data object
if(so.data.your_property != undefined){
      // trace it
      trace(so.data.your_property);
} else {
      // if not, then save it
      so.data.your_property = your_value;
      // write the cookie
      so.flush();
}

more info: http://www.macromedia.com/support/flash/action_scripts/local_shared_object/index.html
0
 
AlexSilvermanAuthor Commented:
I have this in a button :

on (press) {
      var so = SharedObjects.getLocal("User_Info");
      so.data.home_phone = _level1.BENCB.Main.BEN_MAIN.Options.HomePhone_txt.text;
      so.data.work_phone = _level1.BENCB.Main.BEN_MAIN.Options.WorkPhone_txt.text;
      so.data.cell_phone = _level1.BENCB.Main.BEN_MAIN.Options.CellPhone_txt.text;
      so.data.pager_number = _level1.BENCB.Main.BEN_MAIN.Options.PagerNumber_txt.text;
      so.data.email_address = _level1.BENCB.Main.BEN_MAIN.Options.EmailAddress_txt.text;
      so.flush();
}

And then this trying to retrieve :

function GetUserInfo() {
    trace("hit Get User Info");
    var so = SharedObjects.getLocal("User_Info");
    if (so.data.home_phone != undefined) {
      trace("defined");
      _level1.BENCB.Main.BEN_MAIN.Options.HomePhone_txt.text = so.data.home_phone;
      _level1.BENCB.Main.BEN_MAIN.Options.WorkPhone_txt.text = so.data.work_phone;
      _level1.BENCB.Main.BEN_MAIN.Options.CellPhone_txt.text = so.data.cell_phone;
      _level1.BENCB.Main.BEN_MAIN.Options.PagerNumber_txt.text = so.data.pager_number;
      _level1.BENCB.Main.BEN_MAIN.Options.EmailAddress_txt.text = so.data.email_address;
    } else {
                trace("not defined");
      _level1.BENCB.Main.BEN_MAIN.Options.HomePhone_txt.text = "###-###-####";
      _level1.BENCB.Main.BEN_MAIN.Options.WorkPhone_txt.text ="###-###-####";
      _level1.BENCB.Main.BEN_MAIN.Options.CellPhone_txt.text = "###-###-####";
      _level1.BENCB.Main.BEN_MAIN.Options.PagerNumber_txt.text = "###-###-####";
      _level1.BENCB.Main.BEN_MAIN.Options.EmailAddress_txt.text = "http://www.hotmail.com";
    }
}

it keeps popping up as undefined, even after i run through the first script to try and initialize the object's data for future use. is there something wrong with this?
0
 
negatyveCommented:
Try:

on (press) {
     var so = SharedObjects.getLocal("User_Info");
     so.data.home_phone = _level1.BENCB.Main.BEN_MAIN.Options.HomePhone_txt.text;
     so.data.work_phone = _level1.BENCB.Main.BEN_MAIN.Options.WorkPhone_txt.text;
     so.data.cell_phone = _level1.BENCB.Main.BEN_MAIN.Options.CellPhone_txt.text;
     so.data.pager_number = _level1.BENCB.Main.BEN_MAIN.Options.PagerNumber_txt.text;
     so.data.email_address = _level1.BENCB.Main.BEN_MAIN.Options.EmailAddress_txt.text;
     // what does this trace ?
     trace(so.data.home_phone);
     so.flush();
}
0
 
AlexSilvermanAuthor Commented:
it is popping out as undefined... but the value of the text field is coming through fine in a trace next to it.
0
 
negatyveCommented:
and this:

on (press) {
     var so = SharedObjects.getLocal("User_Info");
     so.data.home_phone = _level1.BENCB.Main.BEN_MAIN.Options.HomePhone_txt.text;
     so.data.work_phone = _level1.BENCB.Main.BEN_MAIN.Options.WorkPhone_txt.text;
     so.data.cell_phone = _level1.BENCB.Main.BEN_MAIN.Options.CellPhone_txt.text;
     so.data.pager_number = _level1.BENCB.Main.BEN_MAIN.Options.PagerNumber_txt.text;
     so.data.email_address = _level1.BENCB.Main.BEN_MAIN.Options.EmailAddress_txt.text;
     // what does this trace ?
     trace(_level1.BENCB.Main.BEN_MAIN.Options.HomePhone_txt.text);
     so.flush();
}
0
 
AlexSilvermanAuthor Commented:
it's tracing out what is thare, that what i meant when i said the text field was coming through fine.
0
 
negatyveCommented:
Now I see, it's:

var so = SharedObject.getLocal("cookie_name");

not

var so = SharedObjects.getLocal("cookie_name");
0
 
AlexSilvermanAuthor Commented:
sweet, thanks.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.