Jump to content

Archived

This topic is now archived and is closed to further replies.

gangwarfare.net

writing to files

Recommended Posts

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?


Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
our you could use the fopen like this.

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

Hope this helps,
Tom

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.