Re: Writing to unique files

From: Date: Mon, 04 Dec 2000 21:43:58 +0000
Subject: Re: Writing to unique files
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-28645@lists.php.net to get a copy of this message
Sure - do this: <? if(!file_exists('/tmp/file_number')) { cat 1 >> /tmp/file_number; $number = 1 } else { $number = cat /tmp/file_number; } $s_number = sprintf("%06d",$number); $fp = fopen('/path/to/file-'.$s_number.'.txt','w'); // write file fclose($f); ++$number cat $number >> /tmp/file_number; ?> No DB required - hope this helps (should work - off the top of my head) --Joe On Mon, Dec 04, 2000 at 09:24:22PM -0000, Louis Aslett wrote: > Hi, > > Does anybody have any neat tricks for a good way to choose unique sequential > filenames in the following format?: > > abc-000001.xyz > abc-000002.xyz > etc .... > > in other words, what fast methods are there for creating a new file which > will be the next in the sequence in a directory where the files follow the > above format? Is there any quicker way than laboriously reading in every > directory entry, extracting the number and then determining the largest > value and adding one!? Also, how can one guard against potential conflicts > (ie two processes running at such a close time that they both select the > same filename)? > > Many thanks in advance! > > Louis > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net ----- Joe Stump, PHP Hacker joestump98@yahoo.com http://www.miester.org/ Need a programmer? http://www.google.com/search?q=%22Joe+Stump%22 ***************************************************************** * RENT THIS SPACE - SEEN BY THOUSANDS EACH DAY! * * Current Sponsor: http://www.smackdown.com * *****************************************************************

« previous php.general (#28645) next »