0

当没有想法时,你应该转向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++;
 }
 ?> 
4

2 回答 2

2

原因如下:

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
于 2012-04-28T15:10:50.713 回答
0
$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 变量更改为您要创建的文件数量...

于 2013-12-11T17:01:25.170 回答