随机图片的代码,真的很简单…
2011年9月2日
随机图片的代码,真的很简单…
这个真的很简单的啊,就是php 302 跳转
t.php list.txt 都是放在网站根目录
图片放根目录下的actgod目录
以我的为例,t.php的代码
代码:
1 |
<?php $arr=file('list.txt'); $n=count($arr)-1; header('Location: http://pic.wufenka.com/actgod/'.$arr[rand(0,$n)]); ?> |
list.txt就是所有图片的列表
用命令
代码:
1 |
ls /img > list.txt |
网上有代码是历编图片文件夹,然后随机选一个图片,这个方法比较耗费cpu
所以我先生成一个list,然后只需要读一个txt就可以了
速度比较快,也不占资源
如果想要方便查看,可以建一个index.html
代码:
1 2 3 4 5 6 7 8 9 |
<script type="text/javascript" language="javascript">// <![CDATA[ document.onkeydown=nextpage function nextpage(event) { event = event ? event : (window.event ? window.event : null); if (event.keyCode==39) window.location.reload();//右方向键 } // ]]></script> <img src="http://pic.wufenka.com/t.php" alt="" /> |
这样用pic.wufenka.com就能打开页面,并且右方向键可以自动换下一个图片..
声明: 本文采用 BY-NC-SA 协议进行授权. 转载请注明转自: 随机图片的代码,真的很简单…