Re: [PHP] create textfile if not existing?
On 29 Apr 2002 at 22:49, Hawk wrote: > 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? What is it that you are trying to achieve? It sounds like you're trying to store temporary data and there's better ways to go about that. CYA, Dave -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] create textfile if not existing?
On Mon, 29 Apr 2002, Miguel Cruz wrote: > Might want to do this instead: > > while (is_file("{$filename}{$startnum}.txt") > $startnum++; And perhaps toss in an extra closing paren ) miguel -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] create textfile if not existing?
On Mon, 29 Apr 2002, SHEETS,JASON (Non-HP-Boise,ex1) wrote: > // get new filename until the filename does not exist > while (is_file($filename)) { > $filename .= $startnum; > } This will give you file names like file1, file11, file111, etc. Might want to do this instead: while (is_file("{$filename}{$startnum}.txt") $startnum++; miguel -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] create textfile if not existing?
If I understand you properly this code will do what you want 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
Re: [PHP] create textfile if not existing?
This works but the "w" means that it writes over whats already in the file (look at the manual about fopen for more details) $new_file = "txt/whatever.txt"; $fh = fopen($new_file , "w"); // write the changed new file fputs ($fh, $new_code); // now close the file fclose($fh); Regards John > 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
Re: [PHP] create textfile if not existing?
Hello, Hawk, You might wanna checkout the "w+" modifier. === At 2002-04-29, 22:49:00 you wrote: === >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 = = = = = = = = = = = = = = = = = = = = Best regards. Eric Coleman [EMAIL PROTECTED] 2002-04-29 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] create textfile if not existing?
On Mon, 29 Apr 2002, Hawk wrote: > 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? http://php.net/fopen miguel -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php