$max=10;//quantity of images $fp=fopen ("img.txt", "r"); $n=fread ($fp)+1; if ($n>$max) $n=1; fclose ($fp); $fp=fopen ("img.txt", "w"); fwrite ($fp, $n); fclose ($fp); print '<img src="pic'.$n.'.gif" />';