# Php: write to text file

**URL:** <https://forum.kirupa.com/t/php-write-to-text-file/9082>\
**Category:** Uncategorized\
**Created:** [December 4, 2002, 1:58pm UTC](https://forum.kirupa.com/t/php-write-to-text-file/9082 "2002-12-04T13:58:54Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jubba](https://avatars.discourse-cdn.com/v4/letter/j/90ced4/32.png) [@Jubba](https://forum.kirupa.com/u/Jubba)\
**Post date:** [December 4, 2002, 1:58pm UTC](https://forum.kirupa.com/t/php-write-to-text-file/9082/1 "2002-12-04T13:58:54Z")

</div>

Does anyone know how to make php write to a text file? I’m assuming h88 knows because he’s a smart guy when it comes to this. I would do a quick search online but I’m on my way out the door to class and I just wanted to post this up to give you all time to respond before I get outta class 🙂

I know how to send and recieve variables in flash using PHP, but I want to send those variables to a text file and save them there…

cheers,  
Jubs:cowboy:

---

<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:** [December 4, 2002, 4:54pm UTC](https://forum.kirupa.com/t/php-write-to-text-file/9082/2 "2002-12-04T16:54:04Z")

</div>

I’ve done this already once in the forums, check the attachment: 🙂

---

<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:** [December 4, 2002, 6:17pm UTC](https://forum.kirupa.com/t/php-write-to-text-file/9082/3 "2002-12-04T18:17:25Z")

</div>

I know you did it before, but I searched and I couldn’t find it. Trust me, I always search for about 45 minutes before I bother to ask a question, because I know anything that I have trouble with has already been done once or twice before. Thanks man, I’ll check it out 🙂

---

<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:** [December 4, 2002, 7:24pm UTC](https://forum.kirupa.com/t/php-write-to-text-file/9082/4 "2002-12-04T19:24:23Z")

</div>

its not working, and I’m not sure why. I get this error message from the PHP when I hit the submit button:

Warning: fopen(“member.txt”, “a”) - Permission denied in /home/livetosk/public\_html/shoutbox/member.php on line 2

Warning: fputs(): supplied argument is not a valid File-Handle resource in /home/livetosk/public\_html/shoutbox/member.php on line 3

Warning: fclose(): supplied argument is not a valid File-Handle resource in /home/livetosk/public\_html/shoutbox/member.php on line 4

---

<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:** [December 4, 2002, 7:35pm UTC](https://forum.kirupa.com/t/php-write-to-text-file/9082/5 "2002-12-04T19:35:45Z")

</div>

Ok, well I changed the fopen(“member.txt”, “a”) to include the whole path to the file:

fopen(“[http://www.livetoskateboard.com/shoutbox/member.txt](http://www.livetoskateboard.com/shoutbox/member.txt)”, “a”)

so now I don’t get those error messages, but now nothing writes to the text file…There isn’t anything in the text file after I hit submit and then go to text…

---

<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:** [December 4, 2002, 7:48pm UTC](https://forum.kirupa.com/t/php-write-to-text-file/9082/6 "2002-12-04T19:48:26Z")

</div>

did you correctly chmod your files?

---

<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:** [December 4, 2002, 8:12pm UTC](https://forum.kirupa.com/t/php-write-to-text-file/9082/7 "2002-12-04T20:12:41Z")

</div>

what should they be set to? I’m just using the defaults…

---

<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:** [December 4, 2002, 8:14pm UTC](https://forum.kirupa.com/t/php-write-to-text-file/9082/8 "2002-12-04T20:14:53Z")

</div>

Well if you are writing to a file it should be something like 777

---

<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:** [December 4, 2002, 8:21pm UTC](https://forum.kirupa.com/t/php-write-to-text-file/9082/9 "2002-12-04T20:21:04Z")

</div>

the text file should be 777? or the php file?

---

<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:** [December 4, 2002, 8:23pm UTC](https://forum.kirupa.com/t/php-write-to-text-file/9082/10 "2002-12-04T20:23:21Z")

</div>

The file you are writing to. Which sounds like the .txt file in this case.

---

<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:** [December 4, 2002, 8:31pm UTC](https://forum.kirupa.com/t/php-write-to-text-file/9082/11 "2002-12-04T20:31:44Z")

</div>

yeah, that was kind of a stupid question. 🙂

---

<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:** [December 4, 2002, 8:33pm UTC](https://forum.kirupa.com/t/php-write-to-text-file/9082/12 "2002-12-04T20:33:20Z")

</div>

Well when it comes to chmodding there is no stupid questions 🙂

My friend accidently chmodded a directory so you couldn’t read, write or execute it… so he couldn’t access the directory or the files in it… he had to call the hosts and have them delete it then start all over…LOL.

---

<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:** [December 4, 2002, 8:36pm UTC](https://forum.kirupa.com/t/php-write-to-text-file/9082/13 "2002-12-04T20:36:32Z")

</div>

still not working…hmmm…

---

<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:** [December 4, 2002, 8:39pm UTC](https://forum.kirupa.com/t/php-write-to-text-file/9082/14 "2002-12-04T20:39:46Z")

</div>

I guess youshould wait for h88 on that one, that sounds like a PHP issue with the invalid arguments with your fputs() and fclose() things, and I don’t know PHP too well.

---

<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:** [December 4, 2002, 8:41pm UTC](https://forum.kirupa.com/t/php-write-to-text-file/9082/15 "2002-12-04T20:41:39Z")

</div>

yeah me either. thats the problem. Yeah I’m just kinda chillin til he gets back…

---

<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:** [December 4, 2002, 9:46pm UTC](https://forum.kirupa.com/t/php-write-to-text-file/9082/16 "2002-12-04T21:46:06Z")

</div>

ahahahah I got it to work! But I had to use a different script. Now its back to your script! Thanks for the push h88, and if I need any more help I’ll be sure to contact you! :):evil: :ninja: :elderly: :cowboy: :beard: :hat:

---

<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:** [December 5, 2002, 12:05am UTC](https://forum.kirupa.com/t/php-write-to-text-file/9082/17 "2002-12-05T00:05:14Z")

</div>

Hmm, working fine here, i think there is an issue with ur host, may be they dun allow global variables.

---

<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:** [December 5, 2002, 12:08am UTC](https://forum.kirupa.com/t/php-write-to-text-file/9082/18 "2002-12-05T00:08:42Z")

</div>

Place this at the top of your script:

```php
extract($_POST);

```

Then you’ll be able to access those variables.

---

<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:** [December 5, 2002, 12:10am UTC](https://forum.kirupa.com/t/php-write-to-text-file/9082/19 "2002-12-05T00:10:41Z")

</div>

Working fine. 🙂

---

<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:** [February 7, 2003, 3:13pm UTC](https://forum.kirupa.com/t/php-write-to-text-file/9082/20 "2003-02-07T15:13:14Z")

</div>

Hi h88, do you mind saving the exmple you did as Flash 5, I think this script is exactly what i need!

Quick question! below in my .txt file I want to load my variable from and then save them or update them to the same .txt file. It is only the count0=1 variable I want to save as want it to work like a click counter! With you example can I just change that part of the .txt file?

&link0=google&url0=http://www.google.com&count0=1  
&link1=yahoo&url1=http://www.yahoo.com&count1=1  
&link2=realitydesigns&url2=http://www.realitydesigns.co.uk&count2=1  
&[link3=actionscript.org](http://link3=actionscript.org)&url3=http://www.actionscript.org&count3=1  
&finished=okay&

Thanks

Kev
