无限循环创建 90,000 个随机文件,但它只创建 10 个



当没有想法时,你应该转向stackoverflow。 这就是我正在做的:)我需要用 90,000 个随机文件填充一个目录(不需要内容),但由于某种原因,我的无限循环脚本只创建大约 10 个文件(从 1-10 个),仅此而已。我做错了什么?

 <?
 $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++;
 }
 ?> 
原因

如下:

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
$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/>";
}

只需将 $NoOfFiles 变量更改为您想要创建的文件数量即可...

最新更新