Topic: file_put_contents with multiple flags (Read 3806 times)
Where are my glasses?
Posts: 21
138 credits Members referred : 0
« on: Aug 01, 2007, 01:32:48 am »
Hello,
is it possible to use file_put_contents with multiple flags? The PHP documentation says:
... flags can take FILE_USE_INCLUDE_PATH, FILE_APPEND and/or LOCK_EX ...
I need the flags FILE_APPEND and LOCK_EX. It's possible to do the same with fopen(), fwrite() and fclose() but I'm looking for a simple and fast solution.
Thank you in advance for your answers.
Best regards, Tim
Global Moderator Community Supporter?
Jedai Sword Master
Gender:
Posts: 6691
34714 credits Members referred : 374
It's time to use PHP5!
« Reply #1 on: Aug 01, 2007, 05:52:52 am »
which php5 version do you have?
I am a metal monkey!
Administrator Community Supporter?
Jedai Sword Master
Gender:
Posts: 5799
46391 credits Members referred : 3
« Reply #2 on: Aug 01, 2007, 08:40:12 am »
Are you looking for something like this?
Code:
<?php $fp = fopen("file.txt", "a+");
if (flock($fp, LOCK_EX)) { fwrite($fp, "Write something here\n"); flock($fp, LOCK_UN); } else echo "Couldn't lock the file !"; fclose($fp); ?>
if (flock($fp, LOCK_EX)) { fwrite($fp, "Write something here\n"); flock($fp, LOCK_UN); } else echo "Couldn't lock the file !"; fclose($fp); ?>
No, I want to use file_put_contents because of its performance and simpleness. To specify my problem: The documentation of PHP says that it's possible to have more than one flag in the third parameter but I don't know exactly how it works. Maybe I need to do that with binary operators?