A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: Edit txt files with PHP

  1. #1

    Edit txt files with PHP

    hi, i want to be able to update a txt file using php script from anywhere.
    This txt file basicly has the data which is referenced in a swf file.

    I am sure its possible to do, but i just lack proper syntax to complete this script.

    bewlow i attach the php scripts which i have been working with.

    If anyone knows an easier syntex or know the reason why its not working please help me out lol


    Test code , i dont know why this isnt working.
    Attached Files Attached Files

  2. #2
    Registered User nunomira's Avatar
    Join Date
    May 2002
    Location
    portugal
    Posts
    7,003
    hi,

    All I had to do to make it work was:

    Change the path to the text file in both php files:
    PHP Code:
    $fn "/path/to/page/test.txt";
    // changed to 
    $fn "test.txt"
    and
    PHP Code:
    url=edit.shtml
    // to
    url=form.php 
    in processscript.php.

    Just place all the files in the same folder, in a php enabled server, and that's it.

  3. #3
    Yes! its working

    Thank you so much for this. I am hoping you can help me again.
    In my text field I have a variable named "Textfield" wich is referenced to get string values from the text file. So "Textfield=blah blah blah my text msg". I want the PHP script to load everything after the "TextField=" and when i update it update everything after "TextField=".

    Is this possible too? Please help out again with the syntex..i am realy thinking about buying php for dummies this time!
    Last edited by raveneye; 04-28-2006 at 10:56 PM.

  4. #4
    Registered User nunomira's Avatar
    Join Date
    May 2002
    Location
    portugal
    Posts
    7,003
    I guess it's this:
    PHP Code:
    <form action="processscript.php" method="post">
    <textarea rows="25" cols="40" name="content">
    <?
    $fn = "test.txt";
    // print htmlspecialchars(implode("", file($fn)));
    $myText = htmlspecialchars(implode("", file($fn)));
    // piece of text you want to remove
    $myPiece = "Textfield=";
    // make sure it's in the begining of your text
    $pos = stripos ($myText, "Textfield=");
    if ($pos === 0)
    {
        // remove the begining so it's not displayed
        $myNewText = substr ($myText, strlen ($myPiece));
    }
    // show the new text (without $myPiece)
    print ($myNewText);

    ?> 
    </textarea><br>
    <input type="submit" value="Change!"> 
    </form>
    and
    PHP Code:
    <?
    $fn = "test.txt";

    // piece of text you want added to the text file
    $myPiece = "Textfield=";
    $content = stripslashes($_POST['content']);

    // add $myPiece to the content
    $content = $myPiece . $content;

    $fp = fopen($fn,"w") or die ("Error opening file in write mode!");
    fputs($fp,$content);
    fclose($fp) or die ("Error closing file!");
    echo "<meta http-equiv=\"refresh\" content=\"0; url=form.php\" />\n";
    ?>
    This allows you to load a variable Textfield from the external text file.
    In Flash MX or later you should use the LoadVars Class to load the variables - are you doing this?
    If you are, the onLoad() method allows you to get the content of Textfield.
    But all of this isn't necessary. You don't need a variable, and instead of onLoad() you can use onData, and get all the content of the text file. I.e., what you had in the first place, just text in a text file, could be read by Flash.

  5. #5
    hey nunomira,

    Thanks again for your reply.

    PHP Code:
    $pos stripos ($myText"Textfield="); 
    This line gave an error not sure why.

    To answer your question, yes, i am using the LoadVars function. It works like a charm.
    Here is a bit of code i am using to load the text from the textfile.

    var myLoadr:LoadVars = new LoadVars();

    Code:
    myLoadr.onLoad = function (success) {
    	if (success) {
    		_level10.loadedInfo.htmlText = myLoadr.TextField;
    Last edited by raveneye; 04-29-2006 at 10:58 PM.

  6. #6
    Registered User nunomira's Avatar
    Join Date
    May 2002
    Location
    portugal
    Posts
    7,003
    ups, stripos is PHP5 only. Use strpos instead.

    In order to see the other options at work (the one with text only in the text file, no variable name/value pair), try this instead:
    code:

    myLoadr.Data = function (txt) {
    if (success) {
    _level10.loadedInfo.htmlText = txt;
    }
    }


  7. #7
    Junior Member
    Join Date
    Apr 2010
    Posts
    1
    ...
    Last edited by HTTP5; 04-11-2010 at 05:56 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center