If I understand you properly this code will do what you want
<?php
// data to write to file
$contents = 'your data goes here';
// filename base
$filename = 'name';
$startnum = '1';
// get new filename until the filename does not exist
while (is_file($filename)) {
$filename .= $startnum;
}
// open the file, write contents and close the file pointer
$fp = fopen($filename, 'w');
fputs ($fp, $contents);
fclose ($fp);
?>
This code will write your contents to a filename with the base of $filename,
if the file already exists it will loop until it finds a free file name and
then use that to write your contents to.
You could improve this code so that it doesn't have to loop through used
numbers every time but I wrote it as an example for you, use it if you wish.
Jason
-----Original Message-----
From: Hawk [mailto:[EMAIL PROTECTED]]
Sent: Monday, April 29, 2002 2:50 PM
To: [EMAIL PROTECTED]
Subject: [PHP] create textfile if not existing?
lets say I have 30 lines of text and I want to store it in a folder called
"txt" with the filename $name.txt and, if $name.txt exists, create a
$name1.txt or similiar?
H�kan
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php