PDA

View Full Version : Flash To PHP To TXT


noname
07-06-2003, 02:01 AM
first sorry i know there are alot of topics like this but i did not under stand alot of them

ok what i would like to do is have flash send some var to a php file and then the php file makes a txt file out of the var so i can load it back into flash

i have this php code that makes a text file but i dont know how to get the var's from flash
<?php
$content = "Name:".$_POST["name"]." Address:".$_POST["address"];
$fp = fopen("myText.txt","wb");
fwrite($fp,$content);
fclose($fp);
?>

Billy T
07-06-2003, 02:27 AM
something like

myVars=new LoadVars();
myVars.address="whatever";
myVars.send("the.php","POST");

cheers

noname
07-06-2003, 03:02 AM
ok i have edited the php code down to what i need ( all i need is to get the var addscore from the flash file to PHP then the PHP file will make the text file with the value of addscore)

<?php
$content = "Name:".$_POST["myVars"];
$fp = fopen("myText.txt","wb");
fwrite($fp,$content);
fclose($fp);
?>

now i have tryed to do it but i dont under stand it so how would i set up the code for my button in flash

somthing like
on (release) {
myVars = new LoadVars();
myVars.address = "addscore";
myVars.send("test.php", "POST");
}


i have no idea what am doing so sorry :(

Billy T
07-06-2003, 03:06 AM
no I think it would be more like

$content_=_"Name:".$_POST["address"];


rest looks ok I think...haven't used .send before...I always use either sendAndLoad or load

check out the reference on these LoadVars methods

cheers

noname
07-06-2003, 03:11 AM
i dont know if it is sending the info or not b/c it still does not make the text file

Billy T
07-06-2003, 04:02 AM
try doing sendAndLoad and echo something (like $content) back to flash to see if the vars are being passed around

noname
07-06-2003, 04:21 AM
i was able to load text by just puting on the first frame
loadVariablesNum ("test.php", 0);

and then in the php file all i have is ( addscore is the name of my text field )
<?php print "&addscore="."Hello here is a test"; ?>

Billy T
07-06-2003, 04:31 AM
and what did that tell you?

noname
07-06-2003, 04:33 AM
Originally posted by Billy T
and what did that tell you?
well it worked by printing out Hello here is a test in the text box

Billy T
07-06-2003, 04:37 AM
sure but that doesnt tell you whether or not your vars are being sent to the php file correctly...

try this

leave the addscore on the stage

then add

sendVars=new LoadVars();
recVars=new LoadVars();
recVars.onLoad=function(ok){
if(ok){
addscore=this.addscore;
}
}
sendVars.address="whatever";
sendVars.sendAndLoad("test.php",recVars,"POST");

I think thats the syntax anyway...

cheers

noname
07-06-2003, 04:46 AM
sendVars.address="whatever";
what do i put in place of the whatever

sorry am a noob when it comes to this stuff

Billy T
07-06-2003, 05:18 AM
just leave 'whatever' and see if it comes back

cheers

Billy T
07-06-2003, 05:20 AM
btw if you are using php 4.3 you will probably need tp change your php to something like

$content=$_REQUEST['address'];

I think...

noname
07-06-2003, 05:43 AM
ok i have no idea what am doing but somhow with changing all the code i almost have it i think

the only part is the php file is not getting addscore but it now makes the txt file

here is what i have plz tell me what you want b/c i lost you on that last part... and yes i do have php4.3

ok i have a text field that is called addscore
in the first frame i have the code
loadVariablesNum ("test.php", 0);
sendVars = new LoadVars();
recVars = new LoadVars();
recVars.onLoad = function (ok) { if (ok) {addscore = this.addscore;}};
sendVars.address = "whatever";
sendVars.sendAndLoad("test.php", recVars, "POST");

and in the php file i have
<?php
$content=$_REQUEST['address'];
$fp = fopen("myText.txt","wb");
fwrite($fp,$content);
fclose($fp);
?>

Billy T
07-06-2003, 05:51 AM
get rid of the

loadVariablesNum ("test.php", 0);

and change the php to

<?php
$content=$_REQUEST['address'];
$fp_=_fopen("myText.txt","wb");
fwrite($fp,$content);
fclose($fp);
print "&addscore=$content";
?>


does 'whatever' still appear in the text box?

noname
07-06-2003, 05:55 AM
does 'whatever' still appear in the text box?
it never did appear in the text box and still does not

now that i change it nothing happend... no txt file

Billy T
07-06-2003, 05:57 AM
up the files and I'll take a look

cheers

noname
07-06-2003, 06:01 AM
here you go

Billy T
07-06-2003, 06:16 AM
theres something wrong with your fopen code

I put and echo above it and the variable came back just fine

maybe your textfile needs to exist...I made a blank one and it all worked fine

also had to remove some _ from the php

cheers

noname
07-06-2003, 06:21 AM
man thank you so much for all your help and taking the time you did and now its time for me to get some sleep

thanks again :)

Billy T
07-06-2003, 06:23 AM
no problem ;)

just a pity freddycodes wasn't around...he could have got you going in 30 seconds

cheers

freddycodes
07-07-2003, 06:19 AM
Most likely the problem was that the system user which the web servers runs under (usually "nobody") does not have permission to create files in the directory you were trying to create it in. Also you can just use


$fp = fopen("myText.txt","w");


YOu don't need the "wb" the b part is for writing binary files.


Just an FYI.