Page 1 of 1

flash & PHP: write TXT file from variables

Posted: Sat Oct 11, 2003 11:07 am
by nando
Hi everybody!

I'm trying to make someting like a simple news manager using PHP and Flash . . . but I'm having problems with the PHP script (newbie!!)!
Could you help me please??

I have a dynamic textfield in flash file where i can write the news and a button (SEND) that sends the variables to a php script.
What I'd like the php file to do is to create or overwrite a txt file whit the variables collected from flash file. But I'm doing something wrong!

Here's the PHP script:

<?
$fp = fopen ("$text.txt"); // TEXT.TXT IS THE FILE I WANT TO OVERWRITE
fwrite($fp,"$newtext"); // NEWTEXT ARE THE VARIABLES I WANT TO WRITE
fclose($fp);
if ($fp) {
echo ("&erro=NONE&msg=TEXT WRITTEN!");
} else {
echo ("&erro=OK&msg=PROBLEM OCCURRED!");
}
?>

With this script the txt file on my server doesn't change!!!
Do you see mistakes? Or I'm doing it comletely wrong?
I would appreciate your help very much since it's weeks that I keep on reading tutorials & forums without any result . . .

thanks everybody
Nando

Posted: Sat Oct 11, 2003 12:03 pm
by Gen-ik
First of all try this.......

Code: Select all

<?php
$pathToFile = $text.".txt";
$fp = fopen ($pathToFile, "r+b");
fwrite($fp, $newtext);
fclose($fp);

if($fp)
{ 
     echo ("&erro=NONE&msg=TEXT WRITTEN!"); 
}
else
{ 
     echo ("&erro=OK&msg=PROBLEM OCCURRED!"); 
} 
?>
...... then double check your Flash code if that doesn't work.

You also need to make sure that the text file 'path' is relative to the PHP file you are using. Flash doesn't actually load up the PHP so the 'path' won't be relative to the Flash file.

Posted: Sun Oct 12, 2003 9:29 am
by nando
Hi Gen-ik!
thanks 4 the fast reply!

Sorry but my english ain't too good (italian nother tongue) and have problems to understand what you mean with this:

"You also need to make sure that the text file 'path' is relative to the PHP file you are using. Flash doesn't actually load up the PHP so the 'path' won't be relative to the Flash file."


This is the script I have in flash:

on (release) {
loadVariablesNum("http://www.nando.tk/news/news.php", "","POST");
url = "http://www.nando.tk/news/text.txt";
nextFrame();
}

The php, flash & txt files are all in the "news folder". Is that you mean?

Hope I'm not annoing you whit this stupid questions. "If the forum was in italian it vould have been much easier . . ."
Thanks again

Nando

Posted: Sun Oct 12, 2003 10:34 am
by Gen-ik
nando wrote: The php, flash & txt files are all in the "news folder". Is that you mean?
Nando
Yes that should be ok.

All I ment to say was that if all of the files were in different folders then you would need to make sure all of the paths to the files were correct.
But as all of the files are in the same folder then you do not need to worry about this :)

Did it work by the way?

Posted: Sun Oct 12, 2003 11:51 am
by nando
THANKS THANKS THANKS!!!!!

Now I understand!!

Can't tell you if it works since I'm working right now and can't upload the files to the server from this PC!

I thank you in advance and shurely let you know if it works!!!

Bye and nice sunday
Nando

Ps: nice website! Hope I can listen to your songs soon (don't have a player on this pc!), even if probably its not my kind of musik (I like reggae/dancehall) i'm curious!