php to .txt to flash

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sleepydad
Forum Commoner
Posts: 75
Joined: Thu Feb 21, 2008 2:16 pm

php to .txt to flash

Post 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.
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Re: php to .txt to flash

Post by Burrito »

sounds like the txt file is actually just being cached in your browser...
sleepydad
Forum Commoner
Posts: 75
Joined: Thu Feb 21, 2008 2:16 pm

Re: php to .txt to flash

Post 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");
?>
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Re: php to .txt to flash

Post 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.
sleepydad
Forum Commoner
Posts: 75
Joined: Thu Feb 21, 2008 2:16 pm

Re: php to .txt to flash

Post 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
Post Reply