# Input/output of text files

**URL:** <https://forum.kirupa.com/t/input-output-of-text-files/64718>\
**Category:** Uncategorized\
**Created:** [September 19, 2004, 5:49am UTC](https://forum.kirupa.com/t/input-output-of-text-files/64718 "2004-09-19T05:49:29Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![hrg](https://avatars.discourse-cdn.com/v4/letter/h/a4c791/32.png) [@hrg](https://forum.kirupa.com/u/hrg)\
**Post date:** [September 19, 2004, 5:49am UTC](https://forum.kirupa.com/t/input-output-of-text-files/64718/1 "2004-09-19T05:49:29Z")

</div>

Hi - can anyone pass along instructions for writing a text file - ie. the content of a variable (array) to a text file for retrieval at a later time?

Thanks!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 19, 2004, 3:16pm UTC](https://forum.kirupa.com/t/input-output-of-text-files/64718/2 "2004-09-19T15:16:21Z")

</div>

You would use PHP for this actually. I’m not the greatest at PHP yet, but I think it’s something like this along with some Actionscript to execute this script.

```php
<?php
 $myVar=$_POST['myFlashVar'];
 $filename = "myTextFile.txt";
 $raw_txt = file_get_contents($myVar);
 
 print $raw_txt;
 
 $fp = fopen($filename, "w");
 fwrite($fp, $raw_txt);
 fclose($fp);
 ?>

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 19, 2004, 3:22pm UTC](https://forum.kirupa.com/t/input-output-of-text-files/64718/3 "2004-09-19T15:22:06Z")

</div>

Does it have to be a text file ? Cause it’s really easy to do this with SharedObject. But you can’t open it up in notepad, but it’s easy to save, update and create.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 20, 2004, 1:20am UTC](https://forum.kirupa.com/t/input-output-of-text-files/64718/4 "2004-09-20T01:20:24Z")

</div>

Thanks for replying. I had a look at shared objects and would have thought the following would have worked. Any idea why it doesn’t?

test\_record = SharedObject.getLocal(“filename.txt”); // open and read a text file  
name\_txt.text = test\_record.data.tname; // set first line to a dynamic text field  
address\_txt.text = rest\_record.data.address; // second line from text file  
trace (“end”)  
stop();

on to PHP

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 20, 2004, 1:09pm UTC](https://forum.kirupa.com/t/input-output-of-text-files/64718/5 "2004-09-20T13:09:39Z")

</div>

the SharedObject file is called \*.sol…so try it with getLocal(“filename”);

But the code itself should work…although don’t forget to actually save it with test\_record.flush(amountofbytes);

🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 20, 2004, 4:41pm UTC](https://forum.kirupa.com/t/input-output-of-text-files/64718/6 "2004-09-20T16:41:52Z")

</div>

> [@neverrain](#):
>
> You would use PHP for this actually. I’m not the greatest at PHP yet, but I think it’s something like this along with some Actionscript to execute this script.
> 
> ```php
> <?php
> $myVar=$_POST['myFlashVar'];
> $filename = "myTextFile.txt";
> $raw_txt = file_get_contents($myVar);
>  
> print $raw_txt;
>  
> $fp = fopen($filename, "w");
> fwrite($fp, $raw_txt);
> fclose($fp);
> ?>
> 
> ```

i am using your code. i am, for some reason, having trouble getting the script to write anything to the file. is this code set up to do that?

\<—edit—\>  
nevermind, i got it.
