fopen(); PHP 5.04

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
IceMetalPunk
Forum Commoner
Posts: 71
Joined: Thu Jul 07, 2005 11:45 am

Post by IceMetalPunk »

If you are only using "w" in the begining so you can create it if it doesn't exist (unless I'm missing something), I'd do something like this in the begining instead:

Code: Select all

if (!file_exists("myfile.ext")) {
fclose(fopen("myfile.ext","w"));
}
That will create a blank file if it doesn't exist, but will not clear the file if it already exists.

-IMP ;) :)
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

IceMetalPunk wrote:If you are only using "w" in the begining so you can create it if it doesn't exist (unless I'm missing something), I'd do something like this in the begining instead:

Code: Select all

if (!file_exists("myfile.ext")) {
fclose(fopen("myfile.ext","w"));
}
That will create a blank file if it doesn't exist, but will not clear the file if it already exists.

-IMP ;) :)
You're right but unfortunately he/she needs to read the data from $fp too ;)
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

You may also want to look into ftruncate($fp, 0) as a method of clearing the file ;)
Post Reply