How can I create a random file name
Moderator: General Moderators
-
andylyon87
- Forum Contributor
- Posts: 168
- Joined: Sat Jan 31, 2004 5:31 am
- Location: Dundee
How can I create a random file name
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.
Code: Select all
<?php
$str = md5(time().MD5(rand(100, 489754)).time());
?>-
andylyon87
- Forum Contributor
- Posts: 168
- Joined: Sat Jan 31, 2004 5:31 am
- Location: Dundee
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
Code: Select all
$thefile = "$str.txt"Code: Select all
$thefile = "$str"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);
?>-
andylyon87
- Forum Contributor
- Posts: 168
- Joined: Sat Jan 31, 2004 5:31 am
- Location: Dundee
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
There are functions in PHP for this:
http://www.php.net/tmpfile
http://www.php.net/manual/en/function.tempnam.php
-Jackson