Solved

PHP text writing issues.

Posted on 2004-11-02
162 Views
Last Modified: 2010-04-03
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.
0
Question by:AlexSilverman
    13 Comments
     

    Author Comment

    by:AlexSilverman
    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
     
    LVL 27

    Expert Comment

    by:negatyve
    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
     
    LVL 27

    Expert Comment

    by:negatyve
    ehehe, I was answering..
    0
     
    LVL 27

    Accepted Solution

    by:
    Oh, if you're planning to save a file on the client machine, you should think about using SharedObject..
    0
     

    Author Comment

    by:AlexSilverman
    just was looking into them.

    how do you use a shared object to write variables to?
    0
     
    LVL 27

    Expert Comment

    by:negatyve
    // 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
     

    Author Comment

    by:AlexSilverman
    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
     
    LVL 27

    Expert Comment

    by:negatyve
    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
     

    Author Comment

    by:AlexSilverman
    it is popping out as undefined... but the value of the text field is coming through fine in a trace next to it.
    0
     
    LVL 27

    Expert Comment

    by:negatyve
    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
     

    Author Comment

    by:AlexSilverman
    it's tracing out what is thare, that what i meant when i said the text field was coming through fine.
    0
     
    LVL 27

    Expert Comment

    by:negatyve
    Now I see, it's:

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

    not

    var so = SharedObjects.getLocal("cookie_name");
    0
     

    Author Comment

    by:AlexSilverman
    sweet, thanks.
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone. Privacy Policy Terms of Use

    Featured Post

    Lean Six Sigma Project Manager Certification

    There are many schools of thought around successful project management, but few as highly regarded as the Six Sigma and Lean methods. With 37 hours of learning, this training will explain concrete processes for increasing efficiency and limiting wasted time and effort.

    In my long career of working as an actionscript developer, I had spent sleepless night often working hard to solve some small problems which actually took a lot of my development time; later found out the solutions to be a line or two. Here are s…
    I have found that much of my time doing support ends up being a constant repetition of the same steps to different people.  Early on I stated using web pages with Frequently Asked Questions (FAQs) to alleviate most of the burden.  Sometimes this jus…
    The goal of the tutorial is to teach the user how to set there setting in Adobe Flash Media Live Encoder and YouTube for optimal video and audio quality.
    The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.

    860 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now