Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/283.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在网页上显示随机图像2分钟,然后更改图像?_Php_Html_Image - Fatal编程技术网

Php 如何在网页上显示随机图像2分钟,然后更改图像?

Php 如何在网页上显示随机图像2分钟,然后更改图像?,php,html,image,Php,Html,Image,我有一个小php脚本,它应该显示一个文件夹中的随机图像,然后每2分钟更改一次图像。我遇到的问题是,我们经常会遇到一个错误: 未找到 错误:无法连接到http://somedomain.com/TV/imgSlider.php 下面是我用来选择随机图像(从名为quotes的文件夹中)显示的脚本,并每120秒刷新一次页面(使用元刷新): 如果您对使用Jquery进行尝试感兴趣,我个人认为这是一种比php更干净的方法,可以尝试以下方法: <script> function cha

我有一个小php脚本,它应该显示一个文件夹中的随机图像,然后每2分钟更改一次图像。我遇到的问题是,我们经常会遇到一个错误:

未找到

错误:无法连接到http://somedomain.com/TV/imgSlider.php

下面是我用来选择随机图像(从名为
quotes
的文件夹中)显示的脚本,并每120秒刷新一次页面(使用元刷新):



如果您对使用Jquery进行尝试感兴趣,我个人认为这是一种比php更干净的方法,可以尝试以下方法:

 <script> 
  function changeImg(min, max) { // create the function for changing the images
        var noi = max - min; // number of images
        var numRand = Math.floor(Math.random() * noi) + min; // randomized number
        $("#banner").find("img").attr('src','pages/gallery/PhotoWall/images/' + ""+ numRand +"" + '.jpg'); // set a new image
    }

    $(function() { // Waiting for the DOM ready
        setInterval(function(){ // create an interval (loop)
        changeImg(101, 120); // the function with paramteters
        },1000); // the interval in millisecondes --> 1000 = 1 second
    });
</script>

函数更改img(min,max){//创建用于更改图像的函数
var noi=max-min;//图像数
var numRand=Math.floor(Math.random()*noi)+min;//随机数
$(“#banner”).find(“img”).attr('src','pages/gallery/PhotoWall/images/'+''+''numRand++'.jpg');//设置新图像
}
$(function(){//正在等待DOM就绪
setInterval(函数(){//创建间隔(循环)
changeImg(101,120);//带参数的函数
},1000);//以毫秒为单位的间隔-->1000=1秒
});

来源:

如果您想刷新页面,可以使用@clonerworks,我只是从未使用过Jquery。我不需要任何花哨的东西,我只需要每隔2分钟显示一个随机图像。@JayBlanchard,我已经在使用元刷新了。问题是,每隔一段时间,它就会抛出我在op中提到的错误,而不仅仅是刷新。好的@DuckPuncher,你的刷新方法不清楚。@JayBlanchard,是的,我应该更清楚这一点。我会更新的,我们可能会走这条路。我的老板用javascript写了一些类似的东西,我们遇到了同样的错误。我几乎确信这是他们用来显示图像的电脑。。。基本上,我们在大楼周围安装了电视来显示图像,他们只是将浏览器设置为全屏模式,显示在电视上,并让图像滑块整天运行。你使用了多少图像?我认为,如果这是您的情况,那么查询滑块将是您的最佳选择。这样,只要图像与页面呈现在同一服务器上,页面就不需要引用,也不应该出现404错误哦!完美的那么我们一定会走这条路线:P谢谢!你也可能对这个网站感兴趣-
 <script> 
  function changeImg(min, max) { // create the function for changing the images
        var noi = max - min; // number of images
        var numRand = Math.floor(Math.random() * noi) + min; // randomized number
        $("#banner").find("img").attr('src','pages/gallery/PhotoWall/images/' + ""+ numRand +"" + '.jpg'); // set a new image
    }

    $(function() { // Waiting for the DOM ready
        setInterval(function(){ // create an interval (loop)
        changeImg(101, 120); // the function with paramteters
        },1000); // the interval in millisecondes --> 1000 = 1 second
    });
</script>