[PHP] create textfile if not existing?

2002-04-29 Thread Hawk

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




Re: [PHP] create textfile if not existing?

2002-04-29 Thread Miguel Cruz

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




Fw: [PHP] create textfile if not existing?

2002-04-29 Thread Richard Emery

Did you even try to develop this application?  It's to easy.
Do so.  If you have problems, then post the code and we'll help you.

- Original Message -
From: Hawk [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Monday, April 29, 2002 3:49 PM
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?

2002-04-29 Thread Eric Coleman

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?

2002-04-29 Thread John Fishworld

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?

2002-04-29 Thread SHEETS,JASON (Non-HP-Boise,ex1)

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




RE: [PHP] create textfile if not existing?

2002-04-29 Thread Miguel Cruz

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?

2002-04-29 Thread Miguel Cruz

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?

2002-04-29 Thread David Freeman

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