I am trying to work with code from 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:
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:
<?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