Page 1 of 1
How can I create a random file name
Posted: Sat Jan 31, 2004 5:31 am
by andylyon87
I want to create a string that will allow me to write and read from a randomly generated txt file. The problem is that I want it to generate a random file at the beginning and the read and write from that file all the way through. It is for a chat room for my friends.
Posted: Sat Jan 31, 2004 5:44 am
by qads
Code: Select all
<?php
$str = md5(time().MD5(rand(100, 489754)).time());
?>
Posted: Sat Jan 31, 2004 12:16 pm
by andylyon87
would I be able to read and write to a file created by the above code(the file being the same each time). How would I reference this in a writetofile function could I use
or
Posted: Sat Jan 31, 2004 12:19 pm
by markl999
Code: Select all
<?php
$str = md5(time().MD5(rand(100, 489754)).time());
$fp = fopen($str, 'w');
fputs($fp, 'Some test text');
fclose($fp);
echo file_get_contents($str);
?>
Posted: Sat Jan 31, 2004 12:23 pm
by andylyon87
Would it be possible to work this into a user form, so that the user inputs the information.
Posted: Sat Jan 31, 2004 12:24 pm
by markl999
Sure, you'de basically just replace,
fputs($fp, 'Some test text');
with
fputs($fp, $_POST['usertext']); for example.
Course i left out all the usual validation/error checking etc..etc.., but that's the theory

Posted: Sat Jan 31, 2004 1:35 pm
by jaxn
whoa, why make it so complicated?!?!?
There are functions in PHP for this:
http://www.php.net/tmpfile
http://www.php.net/manual/en/function.tempnam.php
-Jackson