flash & PHP: write TXT file from variables

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
nando
Forum Newbie
Posts: 3
Joined: Sat Oct 11, 2003 11:07 am
Location: Switzerland

flash & PHP: write TXT file from variables

Post 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
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post 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.
nando
Forum Newbie
Posts: 3
Joined: Sat Oct 11, 2003 11:07 am
Location: Switzerland

Post 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
Gen-ik
DevNet Resident
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Post 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?
nando
Forum Newbie
Posts: 3
Joined: Sat Oct 11, 2003 11:07 am
Location: Switzerland

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