PDA

View Full Version : writing file then opening to read again


skjc
04-14-2006, 02:19 PM
i write a file using php from flash and if i want to see the updated file i have to close the browser window, reopen it and its there.

if i dont close the browswer window and just search for it again i get the old file details even if i press ctrl-f5 to refresh the window.

i guess its buffered or in memory?

is there anything i can do in php to refresh the file details - or anything i can do coz closing/opening the browswer window is not an option

thank you

jsebrech
04-14-2006, 03:11 PM
You can always append some meaningless stnig to the URL:
http://someserver.com/somepath/somefile.html?random=5456841

Where you add a unique number after random= for every request. If there's caching involved, that will work around it.

skjc
04-14-2006, 04:15 PM
well i am a novice at php - all i do is send the file and write it in php - where would i put this meaningless string and can php generate a random number or do i have to pass it one from flash

sorry for the questions and thank you very much for the reply

i_am_a_lazy_man
04-14-2006, 05:32 PM
uncache content passed from php in your php file.

<?php
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
?>

skjc
04-14-2006, 11:38 PM
if i include the code in my php page it gives an error for each line as:

Warning: Cannot modify header information - headers already sent by (output started at /files/home1/mypage/wip/index.php:10) in /files/home1/mypage/wip/index.php on line 11

i_am_a_lazy_man
04-15-2006, 04:26 AM
The piece of code must be applied at the top portion of your php script before anything else and also, you can only have one 'header type' within a php file given example below; all in one php file:

<?php
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
?>
<?php
.....
.....
echo......
?>


If all fails, you post your complete php script here.

skjc
04-15-2006, 07:49 AM
i took everything else out of the page all i have left is the php script and the errors are still there.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>cgi index page</title>


</head>
<body>
<?php
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");

?>
</body>
</html>



thank you again

i_am_a_lazy_man
04-15-2006, 12:04 PM
like i said, put it on top of everything else. i assume the source you gave is in .php extension. you apply the no-cache statements before the output takes place.


<?php
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>cgi index page</title>


</head>
<body>
.....
</body>
</html>

skjc
04-15-2006, 03:19 PM
thank you - no more errors. when you said the top i stupidly thought the top of the php script not the page itself.

anyhow, same issue even with ctrl-f5 the file details are still the old ones, have to close and open the browswer window to see the new ones :(

(yes .php extension - index.php).

the form that handles receiving the file and writing is:

[QUOTE][<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>


<body>

<?php
echo "&result=" . $_POST['fname'] . " saved";
$file = fopen($fname, 'w');
fwrite($file, "$ffile");
fclose($file);
?>

</body>
</html>/QUOTE]

i use sendAndLoad from flash - works fine except for the closing/opening the browswer window to see the new file changes.

jsebrech
04-18-2006, 07:50 AM
See this thread (http://actionscript.org/forums/showthread.php3?t=99193&highlight=cache+php) for how to append a unique suffix.

skjc
04-18-2006, 10:40 AM
thank you jsebrech.

i added the code but i just dont get it. in the example he has myXml.load and the a php file. does this mean that there is a php script handling the load somehow.

just adding the random number to the load (with an xml file) will not work as it just adds it to the filename and then of course it does not exist.

sorry for being such a dumbass - dont know why i just cant get this one.

myXML.load(controller.xmlInput_txt.text + new Date().getTime());

jsebrech
04-18-2006, 11:39 AM
myXML.load(controller.xmlInput_txt.text + "?unique=" + new Date().getTime());

skjc
04-18-2006, 05:55 PM
thank you so very very much - it works brilliantly.

it has been stopping me from moving forward and now its fine - i must read up on the "?unique = " part as i dont know anything about it (didn't even know it existed).

thank you again - very much appreciated

jsebrech
04-19-2006, 07:40 AM
It's a HTTP GET argument. It's a way of passing information to dynamic webpages (PHP scripts, Perl scripts, ...). You append the filename with "?variablename1=value1&variablename2=value2&...". If the webpage in question doesn't do anything with the variable, it will be ignored, but, since the URL is unique, it won't fetch it from cache, but will regenerate it.

i_am_a_lazy_man
04-27-2006, 02:06 PM
Sorry, I'm late. Been busy with my work. Glad you got the solution already. I see now you're actually reading the xml file directly and not through the php script. You can still use the 'uncache' statements provided you read the xml content from the php script (a new one with the top of header put as uncached) instead of the xml file. The advantage of using uncache through php script is that the xml file content will not be physically existed in your internet temporary folder.