使用php和javascript进行动态幻灯片放映 [英] Dynamic slide show using php and javascript

查看:91
本文介绍了使用php和javascript进行动态幻灯片放映的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用此代码在幻灯片中显示图像,并且图像的选择是动态的...但是它仅填充第一个图像,而不提取其他图像...请指导我错误在哪里?

I am using this code to display images in slide show and the selection of images is dynamically... But it is populating only the first image and does not fetch other images... Please guide me where is the error?

PHP Code:
<?php

    header("content-type: application/x-javascript");



    function returnimages($dirname=".") {

        $files = array();

        $curimage = 0;



        //valid image extensions

        $pattern="(\.jpg$)|(\.png$)|(\.jpeg$)|(\.gif$)";



        if($handle = opendir($dirname)) {

            while(false !== ($file = readdir($handle))) {

                if(eregi($pattern, $file)){

                    echo 'galleryarray[' . $curimage . '] = "' . $file . '";';

                    $curimage++;

                }

            }



            closedir($handle);

        }



        return($files);

    }



    //Define array in JavaScript returnimages()

    //Output the array elements containing the image file names



    echo 'var galleryarray = new Array();';

?>

HTML Code:
<html>
    <head>
        <title></title>
        <script src="pics/getimages.php"></script>
        <script type="text/javascript">
            var galleryarray = returnimages();
            var curimg = 0;

            function rotateimages(){
                var imagesDirectory = "pics/" + galleryarray[curimg];
                document.getElementById("slideshow").setAttribute("src", imagesDirectory)
                curimg = (curimg < galleryarray.length - 1) ? curimg + 1 : 0

            }

            window.onload = function(){

                setInterval("rotateimages()", 2500)

            }

        </script>
    </head>
    <body>
        <img width="468" height="312" id="slideshow" src="..._web\pics\seal.jpg">
    </body>
</html>

推荐答案

dirname =" ) { span>
dirname=".") {


文件 > array(); span>
files = array();


curimage > 0; span> //有效 图像 扩展名 span>
curimage = 0; //valid image extensions


这篇关于使用php和javascript进行动态幻灯片放映的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆