Jump to content


Photo

writing to files


  • Please log in to reply
3 replies to this topic

#1 gangwarfare.net

gangwarfare.net
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 16 August 2006 - 09:39 PM

im new to php, and im trying to make a few scripts for my site,

im tryin to write to a file

<?php
$information = "blah blah";
$handle = fopen('$username.php', 'w+');
fwrite($handle, $information);
?>

this script will run everytime someone fills in a form.
what i want to do, is each time a user submits the form, is to creat the file according to their username, then add some data, this includes varibles

for example if a user wi the name test filled in the form

i want to write on the file:
<?
$user=test
$email=test.... etc...
?>

how would i go about gettin this to happen?




#2 GingerRobot

GingerRobot
  • Staff Alumni
  • Advanced Member
  • 4,086 posts
  • LocationUK

Posted 16 August 2006 - 09:42 PM

So you know how to write to files already?

Well then all you should need to know is how to create them:
http://uk2.php.net/touch

#3 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 16 August 2006 - 09:50 PM

our you could use the fopen like this.

$filename = "path/to/file/$username.whatever";
$fp = fopen($filename, "x+b");
$somecontent = //your posted results
fwrite($fp, $somecontent);
fclose($fp);

Hope this helps,
Tom

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#4 GingerRobot

GingerRobot
  • Staff Alumni
  • Advanced Member
  • 4,086 posts
  • LocationUK

Posted 16 August 2006 - 09:57 PM

Oh yeah, i forgot that fwrite would create the file if it didn't exist.

I would think that is a better solution because you can write to it at the same time.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users