External .txt

Hey guys.
I saw this tutorial on Flashkit.com and I have a couple of questions:

The tutorial

All I want to do is have an a form where users can input their email address and then the email address will be stored in a .txt file in my directory. My question is at the end the tutorial gives some lines of code that looks like this:

On (Release)
Load Variables (“http://www.server.com/cgi-bin/myform.cgi”, 1, vars=POST)
End On

I have no experience with cgi, so is all I do save a .txt file as .cgi and name it myform, and then place it in my directory. And then I replace server.com with the address of my site?

Thanks guys!

not quite. Your flash movie is sending its variables to the cgi script. The cgi script is actually going to write to the text file.

I don’t have a .cgi file or anything in my directory. So is the file going to automatically make a .txt file and start adding the addresses? Also, is there a way to do this without cgi? Can I just have the variable sent to a .txt file in my directory?


A cgi or php file is needed to communicated between the text and flash file. Strange that the cgi file isn’t included for download on this tutorial.

Hmmm…Do you know of another tutorial where I could get the file?


I’m still looking for a tutorial on how to store vairables in a .txt file. I am just trying to move this post up.


Hello bcogswell11,

do you have access to PHP on your server? It’s quite easy to write to a file or create a new file using PHP. If you do have access to it, let me know and we can discuss the details.


Yes I do have PHP access. Thanks for your help. I have looked all over the internet and I can’t find what I need. All I want is an input box that stores a variable in an outside file. In this case, the variable will be email addresses. This way, I can go to the outside file and just have the long list of addresses that I can move to my E-mail.


Part 1: Sending vars from Flash to PHP

To do this you need to create a dynamic text box and give it a variable name (not an instance name!). Name it something like e-mail. Now, create some sort of submit button and attach the following code to it (assuming you’re using MX):

on(release) {
  dataContainer = new LoadVars();
  dataContainer.email = email;
  dataContainer.send("http://path/to/host/write.php", "sendWindow", "POST");

Part 2: Writing Flash vars to file with PHP

Create a new PHP file named write.php and insert the following code:

  $file = "path/to/file/to/write/to";
  $handle = fopen($file, "a");
  fwrite($handle, "

*If $_GET isn’t working for you, don’t fret. Use $HTTP_POST_VARS[email] instead.

As you can see, it’s quite a simple process. I had problems when I tried this on my host. They told me fwrite() wasn’t permitted. If this is the same with your host, simply add a shebang line to the path of php on the host and you will probably be able to access fwrite(). I can’t guarantee that it will work but I know it did for me.

Let me know how things turn out.



As I am doing this I am trying to understand the process as well. In write.php I am telling Flash to store the variable in the .txt file right?

Other than that I understand the whole thing. My site will be up tomorrow night and I will see if it works and let you know. Thank you for your help!


Actually Flash has no part in thr writing process. It is simply defining the value of the email address that will be written to a file by the PHP script. Flash just passes that value to the write.php file. If Flash could write to files, there would be no need for PHP in this case.