User-Profile-Image
hankin
  • 5
  • 首页
  • 分类
    • Windows
    • Web
    • VoIP
    • Virtualization
    • Trading
    • Smart Home
    • SEO
    • Security
    • Python
    • Program
    • PHP
    • OSX
    • OS
    • OpenSource
    • Nginx
    • MySQL
    • Mood
    • Linux
    • Life
    • Injection
    • Hosting
    • Finance
    • Exploits
    • CDN
  • 页面
    • About
  • 友链
    • 维酷科技
    • Tesra超算网络
Help?

Please contact us on our email for need any support

Support
  • 首页
    首页   ›   Program   ›   PHP   ›   正文
PHP

PHP随机显示图片

2011-08-26 00:07:58
2266  0 0

pic.php list.txt放在网站根目录

pic.php内容如下:
<?php
$arr=file('list.txt');
$n=count($arr)-1;
header('Location: https://prodigyu.com/pic/'.$arr[rand(0,$n)]);
?>

list.txt就是所有图片的列表
用命令

ls /图片所在文件夹 > list.txt

网上有代码是历编图片文件夹,然后随机选一个图片,这个方法比较耗费cpu
所以我先生成一个list,然后只需要读一个txt就可以了
速度比较快,也不占资源
如果想要方便查看,可以建一个index.html

<script language=javascript>
document.onkeydown=nextpage
function nextpage(event)
{
event = event ? event : (window.event ? window.event : null);
if (event.keyCode==39) window.location.reload();//右方向键
}
< /script>
< img src="https://prodigyu.com/pic.php" alt="" />

评论 (0)

Click here to cancel reply.

欢迎您 游客  

    ProdigYu
    180文章 77评论 4点赞 554001浏览
    随机文章
    CentOS下Xen虚拟机的安装与配置
    15年前
    11月的百度SEO心得
    13年前
    头文字D第五季
    13年前
    Windows自带工具实现端口转发-netsh
    9年前
    Spawn-fcgi启动进程马上死掉
    15年前
    Tags
    Apache CentOS CMD DDOS Debian DNS Docker FastCGI Google IIS IP iptables Linux Mac MySQL Nginx Opensource PHP Python Skill SSH Ubuntu Vim VMware VPN web.py Windows 删除 命令 命令提示符 安装 开源 技巧 插件 漏洞 百度 系统 组件 终端 缓存 网络电话 脚本 自建 详解 错误
    Meta
    • Log in
    • Entries feed
    • Comments feed
    • WordPress.org
    Copyright © 2025
    主页
    页面
    • About
    博主
    ProdigYu 管理员
    Something about myself
    180 文章 77 评论 554001 浏览
    测试
    测试