View Full Version : Hiw would I send this to PHP?
Legolas
04-04-2004, 12:50 PM
I have a varible, "_root.data" that I wish to send to PHP ro be written to a file. Im not sure how I should do this. Currently my php code looks like:
writeForums.php
<?php
$data = $_POST['data'];
$fp = fopen("forums.xml", "w+");
fwrite($fp, $data);
fclose($fp);
?>
and my AS:
On a button nested within movieClips
_root.data = xml;
send("writeForums.php", "POST");
I've never used flash and php together, although Ive used both seperate. I would appreciate it if someone could Help
CyanBlue
04-04-2004, 02:01 PM
You'd need to specify the LoadVars object before you send it to the PHP script...data_lv = new LoadVars();
data_lv.data = xml;
data_lv.send("writeForums.php", "_blank", "POST");Mind you that send() function WILL open a new browser... If you want to get away from it, you'd need to use sendAndLoad() function...
Legolas
04-04-2004, 02:18 PM
I could've sworn an older tutorial omitted the "var = new LoadVars();" line. Is that new with AS2? Also thanks for the sendAndLoad() tip. Thanks for helping to quickly!
Legolas
04-04-2004, 02:23 PM
On the same note with updating dynamically using php like that, is there a way to
Stop the flash from caching (Ill search for this, I remember someone said it could be done)
Stop the PHP page from caching. On this note, I found this code which (I think) does that:
header("Expires: ".gmdate("D, d M Y H:i:s")."GMT");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
but I've never had the need to use the php "header()" function to set html headers, so Im not sure it thats correct
CyanBlue
04-04-2004, 02:26 PM
Yeah... That could work on some cases, but not all of the cases, I heard... I think you probably see some of the samples of that header() line if you search with 'freddycodes' within this forum...
As for no cache in Flash, you can call it with random argument like this...data_lv.send("writeForums.php?uniqueID=" + getTimer(), "_blank", "POST"); That 'uniqueID' can be anything as long as you do not use that word in PHP...
Legolas
04-04-2004, 02:35 PM
I had previously done that to keep files to not cache, but I wondered if there was a 'real' way to stop it from cacheing.
I mean is there a way to stop the swf from caching from within the movie. Its annoying to have to clear my cache every time I attempt to test the movie on the Apache server (on this pc for testing php files).
Well, its writing to the file now, but its writing a blank file. Im pretty sure when I trace xml I get the result I want, though. Might I need xml.toString()?
Legolas
04-04-2004, 02:39 PM
okay, now I got it to write the updated file, but now It replaces "s needed in the xml file with
escape character(\)"
I want the \ to be there for new lines, etc, but not for ""s. How could to do this?
Thanks a million;
Legolas
CyanBlue
04-04-2004, 02:46 PM
Well... That's more than my brain weighs... I know that there is a function to strip out the slashes (stripslashes), but I don't think it can be selective... Maybe you've got to use RegEx to do the conversion by yourself...
As for the cache... No, we are stuck with that... :(
Legolas
04-04-2004, 02:53 PM
Are there any workarounds for the caching of the swf?
[edit]I got stripslashes to work great! Now flash reads it after you refresh the list using the refresh button in my swf!
Legolas
04-04-2004, 03:24 PM
Its working great now because of you, CyanBlue, thanks (I didnt even need to use the no cache trick for the php page, and it still works fine). Theres only one gripe I have. Even using:
data_lv = new LoadVars();
data_lv.forumData = xml.toString();
data_lv.sendAndLoad("writeForums.php", "POST");
A blank window still pops up, and I dont know why.
2nd:
Is there some code that could replace each instance of "\l" and "\n" with "<br />"? If not ill have to use a loop and explode in php. Id prefer this to be in php, so it doesnt slow the flash application.
CyanBlue
04-04-2004, 06:12 PM
Well... A blank window is popping up because that's how you have specified... Try this...data_lv.sendAndLoad("writeForums.php", data_lv, "POST");
As for the <BR> tag... You could take a look at nl2br() function in PHP... If that does not work, you'd need to either use RegEx or loop through the content of the strings...
Legolas
04-04-2004, 07:07 PM
One last question for today (as I am sure you are glad): What could I do to stop the need to reload the entire browser window to see any changes after the XML is changed. I have a reload button that retransfers the data from the XML file, but you must reload the page for it to update. I have a strange feeling it's either: (a)Caching the xml file or (b) for some reason not getting the changes. I think it's (a) because you still recieve what was there before the update. However, I can't get the standard:
xxxx.yyy?zzz=[# genorated from date & time]
to work with xml files. This could have just been an error from me appending it, however.
I decided to not tackle the linebreaks in textboxes yet, or atleast until I get the two main update functions fairly polished off.
Since you helped me so much, would you care to take a look at what's done in a day or two?
CyanBlue
04-04-2004, 11:37 PM
Well... Obviously, I do not have much experience with dynamic XML file, but if you could provide some sample that we can fiddle with, I am sure we can find the solution to it... :)
Legolas
04-05-2004, 12:51 PM
Sure, Ill post a version of what I have. The odd thing was that it worked for abit, but than it started to require refreshes. Dont ask me :confused:
|
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.