Page 1 of 1

php to .txt to flash

Posted: Wed Jan 21, 2009 9:32 am
by sleepydad
I have created a Flash file that sends text to a flat .txt file via php and displays the contents of the entire .txt file in a separate window. Basically it's a sign up sheet for a sports team. I'm capturing the data in Flash using:

Code: Select all

 
// on submit:
myVars=new LoadVars();
my Vars.name=name_txt.text;
myVars.sendAndLoad("sendinfo.php", myVars, "POST");
 
 
my php reads:

Code: Select all

 
<html>
<body>
<?php
// To reset the .txt file via admin interface //
$evaluate=$_POST['evaluate'];
if($evaluate=="admin") {
$open = fopen("savedinfo.txt","w+");
$text = "blog=";
fwrite($open, $text);
fclose($open);
/////////////////////////////////////
} else {
$user = $_POST["name"];
$out = fopen("savedinfo.txt", "a");
fputs ($out,implode,("\n"));
fwrite($out, $user."\n");
fclose($out);
}
?>
</body>
</html> 
 
THE PROBLEM:

It will eventually update the .txt file, eventually meaning anywhere from 1-5 minutes. However, if I open the text file in a separate browser window and hit refresh it will update immediately and send the data back to my Flash presentation. I'm wondering why the delay unless I kick start it in the browser. How can I get instant gratification and have the text file update immediately without intervention through the browser. My Flash presentation is time sensitive and the information displayed needs to be current and immediate.

Thanks in advance for suggestions.

Burrito: Please use PHP tags when posting code in the forums.

Re: php to .txt to flash

Posted: Wed Jan 21, 2009 9:41 am
by Burrito
sounds like the txt file is actually just being cached in your browser...

Re: php to .txt to flash

Posted: Wed Jan 21, 2009 10:20 am
by sleepydad
Would this solve my problem? It's something that I googled:

<?php
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
?>

Re: php to .txt to flash

Posted: Wed Jan 21, 2009 10:42 am
by Burrito
that would help for a .php file but not for a .txt file. You could use that in a .php file and then read in your .txt file to that php file to view its contents.

check out fopen() or file() or file_get_contents() to figure out how to read your txt file in to php.

Re: php to .txt to flash

Posted: Wed Jan 21, 2009 4:30 pm
by sleepydad
Believe it or not, I think it worked on the first try using file_get_contents(). That seems to have kick started my .txt file and instead of calling the info from the .txt, I've instructed a separate php to echo the .txt and Flash to call in that echo...whew! Round about perhaps, but it seems to be working (knock wood). Just to be on the safe side, I also included the headers that I mentioned in the previous thread in the new php file.

Thanks for the suggestion, Burrito!

sleepydad