# Flash/PHP write to .txt not working

**URL:** <https://forum.kirupa.com/t/flash-php-write-to-txt-not-working/311861>\
**Category:** programming\
**Created:** [July 19, 2010, 1:38am UTC](https://forum.kirupa.com/t/flash-php-write-to-txt-not-working/311861 "2010-07-19T01:38:24Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknownelementx](https://avatars.discourse-cdn.com/v4/letter/u/85f322/32.png) [@unknownelementx](https://forum.kirupa.com/u/unknownelementx)\
**Post date:** [July 19, 2010, 1:38am UTC](https://forum.kirupa.com/t/flash-php-write-to-txt-not-working/311861/1 "2010-07-19T01:38:24Z")

</div>

I am trying to work with code from [http://www.kirupa.com/forum/showthread.php?t=306368](http://www.kirupa.com/forum/showthread.php?t=306368)

that uses a php script to read from and write to a file called “text.txt” using the php file “write.php”. I took a break from this project for the past two weeks and just got back to it. For some reason the flash files no longer are writing to my .txt files. I know I have gotten it to work before, but can’t figure out why they aren’t working now.

here is the flash code:

```auto
import flash.events.*;
import flash.net.URLLoader;
import flash.net.URLLoaderDataFormat;
import flash.net.URLRequest;
stop();

var variables:URLVariables = new URLVariables();
var varSend:URLRequest = new URLRequest("write.php");
var varLoader:URLLoader = new URLLoader;
varSend.method = URLRequestMethod.POST;
varSend.data = variables;

bt_sub.buttonMode = true;
bt_sub.addEventListener(MouseEvent.CLICK, ValidateAndSend);

function ValidateAndSend(event:MouseEvent):void

{
   
    gotoAndPlay(2);
     variables.wootext = text_txt.text;

           varLoader.load(varSend);
   
}

var url:String = "test.txt";
var loadit:URLLoader = new URLLoader();
loadit.addEventListener(Event.COMPLETE, completeHandler);
loadit.load(new URLRequest(url));

function completeHandler(event:Event):void
{
text_txt.text = event.target.data as String;   
}

```

here is php:

```auto
<?php

$wootext = $_POST['wootext'];

// Strip slashes on the Local variables
$wootext = stripslashes($wootext);

$filename = 'test.txt';
$somecontent = "Add this to the file
";
$somecontent2 = "Add this to the file2
";
// Let's make sure the file exists and is writable first.
if (is_writable($filename)) {

    // In our example we're opening $filename in append mode.
    // The file pointer is at the bottom of the file hence
    // that's where $somecontent will go when we fwrite() it.
    if (!$handle = fopen($filename, 'wb')) {
         echo "Cannot open file ($filename)";
         exit;
    }

    // Write $somecontent to our opened file.
    if (fwrite($handle, $wootext) === FALSE) {
        echo "Cannot write to file ($filename)";
        exit;
    }

    echo "Success, wrote ($wootext) to file ($filename)";

    fclose($handle);

} else {
    echo "The file $filename is not writable, or doesn't exist";
}
?>

```

thanks for the help
