Rand and file_put_contents

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

Post Reply
smadonnatore
Forum Newbie
Posts: 1
Joined: Fri Dec 30, 2011 5:29 pm

Rand and file_put_contents

Post by smadonnatore »

I'm going mad.
Here it is a single line code snippet

Code: Select all

<?php
file_put_contents("/var/www/test/" . rand() . ".html", "test");
?>
It should create 1 file with content "test", but every times it's executed it creates 2 files with the same content.
How is it possible?

Thanks.
User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

Re: Rand and file_put_contents

Post by twinedev »

As is, the code above would not do that. How is that line of code (and/or the file it is in) called?

-Greg
gameraider
Forum Newbie
Posts: 6
Joined: Thu Dec 29, 2011 6:14 am

Re: Rand and file_put_contents

Post by gameraider »

smadonnatore wrote:I'm going mad.
Here it is a single line code snippet

Code: Select all

<?php
file_put_contents("/var/www/test/" . rand() . ".html", "test");
?>
It should create 1 file with content "test", but every times it's executed it creates 2 files with the same content.
How is it possible?

Thanks.
Did you set the FILE_APPEND flag ??
Post Reply