Page 1 of 1

PHP write to text file

Posted: Tue Jun 11, 2013 10:49 am
by chris98
Hello, I am currently working on a website, and I want to create an uploads section.I have got this working, however now I would like to put the Users Username who has uploaded something into a text file in the same location as the upload.I have tried for ages, and was wondering if anyone knows how?

Re: PHP write to text file

Posted: Tue Jun 11, 2013 12:11 pm
by requinix
Any reason you're not using a database? That's the best place for that kind of information.

Re: PHP write to text file

Posted: Tue Jun 11, 2013 12:29 pm
by Christopher

Code: Select all

$file = '/path/to/some/file.txt';
$username = 'foobar';
file_put_contents($file, $username);
You need write access to that directory, which I assume you have since you are uploading files to it.

Re: PHP write to text file

Posted: Sat Jun 15, 2013 3:21 am
by chris98
Thanks, I can get it to work now!