;

PDA

Click to See Complete Forum and Search --> : php/flash mailing list (solution should be easy)


woj1s
12-14-2007, 04:10 PM
I am using a mailing list that works great. The php writes to a text file on my server and im able to open the text file and read the submitted content.

HOWEVER, Everytime I submit content, the php just replaces/rewrites info in the text file instead of adding to it. The solution should be rather easy but I cant find it anywhere.

Actionscript:
function saveText() {
// create your VAR OBJECT
sendText = new LoadVars();

// Format variables for PHP
sendText.nameData = "&nameData="+_root.nameData;
sendText.emailData = "&emailData="+_root.emailData;
sendText.newFileName = "text1.txt";

//tell our script what to do WHEN/IF everything goes ok.
sendText.onLoad = function(success) {
if (success) {
//response is the variableName echo'd in the PHP file.
_root.saveResponse = sendText.response;
_root.response_txt.text = sendText.response
}
};
//finally call the PHP the script
sendText.sendAndLoad("savedData/saveMyText.php", sendText, POST);
}

Button code:
on (release) {
_root.nameData = textField1.text;
_root.emailData = textField2.text;
_root.saveText(); //function that does sendAndLoad for vars.
}

PHP:
<?php

$newFileName=$_POST["newFileName"]; //Folder HAS to have CHMOD permissions of 777

$nameData=$_POST["nameData"];

$fp = fopen ("text1", "w");

if($fp)
{ fwrite($fp,stripslashes("$nameData\n$emailData")); // check to see if open was ok.
fclose($fp);
echo ("&response=Successfully!");
} else {
echo ("&response=Unsuccessfully!");
}

?>

Musicman
12-14-2007, 04:59 PM
Hi,

in the php it is as simple as
$fp = fopen ("text1", "a");

Depending on how you want to use this, it might be better to change the flash to omit these parts "&nameData="+ and perhaps find a different layout for the text file too. In any case, you cannot really read it back into flash with multiple "&nameData=" entries ... you would only get the last

Musicman