Reputation: 3514
when out of ideas, thou shall turn to stackoverflow. so that's what i'm doing :) i need to fill up a directory with 90,000 random files (no content needed) but for some reason, my infinite loop script is only creating about 10 files (from 1-10) and nothing more. what am i doing wrong?
<?
$counter = 1;
while ($counter < 90000) {
$rand = rand(1, 9999999999999999999999);
print (" counter = " . $counter . "<BR>");
$ourFileName = "$rand";
$ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");
fclose($ourFileHandle);
$counter++;
}
?>
Upvotes: 0
Views: 469
Reputation: 65
$NoOfFiles = 10;
for($i = 0; $i < $NoOfFiles; $i++){
$FileHandler = fopen($i.".txt", 'w') or die("can't open file");
fclose($FileHandler);
echo "File '". $i.".txt' has been created<br/>";
}
Just alter the $NoOfFiles variable to however many files you want creating...
Upvotes: 0
Reputation: 360752
Here's why:
php > $x = 9999999999999999999999;
php > echo $x;
1.0E+22
php > echo rand(1, 9999999999999999999999);
1
php > echo rand(1, 9999999999999999999999);
1
php > echo rand(1, 9999999999999999999999);
1
php > echo rand(1, $x);
1
Upvotes: 2