这是我做的一个计数器,东西小,功能不全但好用。
<?
$count=0;
$counter_file="count.txt";
if(file_exists($counter_file))
{
$fp=fopen($counter_file,"r");
$count=0+fgets($fp,20);
fclose($fp);
}
$count++;
$fp=fopen($counter_file,"w");
fputs($fp,$count);
fclose($fp);$fp = fopen ($counter_file, "r");
$array_count = 1;
while (!feof($fp))

$count= fgetc($fp);
$counter_array[$array_count] = $count;
$array_elements = count ($counter_array);
$array_count = $array_count + 1;
}for($array_id=1;$array_id<$array_elements;++$array_id) 
{
?>
<img src="images\<?=$counter_array[$array_id]?>.gif">
<?
}
?>
建立一个count.txt文件,然后在images文件夹中放入1-9.gif图片就可以了。

解决方案 »

  1.   

    'w+' - Open for reading and writing; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it. 你用w+来打开文件, 所有内容都不见了, 当然不行.正确方法是: 用r打开文件读, 关闭后, 用w打开文件写.也就是 mxlmwl(飞星) 的操作方法.
      

  2.   

    文件读写没什么问题了,可是还是无发显示图片,应该是$num[$h]的问题.改用飞星的方法可以显示!
    能请教一下
    ?>
    <img src="images\<?=$counter_array[$array_id]?>.gif">
    <?
    这条语句的用法吗,
    还有怎么open了文件不用 close呢?
      

  3.   

    echo"<img src=$num[$h].gif>"; 
    改为
    ehco"<img src=".$num[$h].".gif>";