显示文件夹中的随机图像,而不重复使用JS或PHP [英] Show Random images from a folder without repeating using JS or PHP

查看:96
本文介绍了显示文件夹中的随机图像,而不重复使用JS或PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在目录中的文件夹中显示10-15个图像,但我不想重复显示它们。我也不想使用MySQL表

I want to show 10- 15 images from a folder in directory but I don't want to show them repeatedly. I also don't want to use MySQL Table

请帮忙。

目前我使用的是以下代码

currently i am using below code

             $imglist='';
             $img_folder = "gallerypage/small/";

              mt_srand((double)microtime()*1000);

             $imgs = dir($img_folder);

             while ($file = $imgs->read()) {
                 $imglist .= "$file"."|";

             } closedir($imgs->handle);
             $imglist = explode("|", $imglist); 
             //print_r($imglist);
             $no = sizeof($imglist)-2;
             //echo $no;

             for ($i=0; $i<=$no; $i++)
             {
             $random = $i; // mt_rand($i, $no/$i);
             //echo $random;
             $fileb = 
             $image = $imglist[$i];
             $fileb = $image; 
                 if($image != '.' && $image != '..' && $image != 'Thumbs.db' )
                 {

                    //echo '<img src="'.$img_folder.$image.'" border=0>';
                    //if($image != ""){
                     //echo "k".$image."k";
                    echo "<a href='".$img_folderb.$fileb."' rel='lightbox-journey'><img src='".$img_folder.$image."' title='".$image."' alt='".$image."'   height='100'/>";
                    //}
                 }
             }


推荐答案

<SCRIPT LANGUAGE="JavaScript">

<!-- Begin
// Set up the image files to be used.
var theImages = new Array() // do not change this
// To add more image files, continue with the
// pattern below, adding to the array.

theImages[0] = '1.gif'
theImages[1] = '2.gif'
theImages[2] = '3.gif'
theImages[3] = '4.gif'

// do not edit anything below this line

var j = 0
var p = theImages.length;
var preBuffer = new Array()
for (i = 0; i < p; i++){
   preBuffer[i] = new Image()
   preBuffer[i].src = theImages[i]
}
var whichImage = Math.round(Math.random()*(p-1));
function showImage(){
document.write('<img src="'+theImages[whichImage]+'">');
}

//  End -->
</script>

</HEAD>

<!-- STEP TWO: Copy this code into the BODY of your HTML document  -->

<BODY>

<SCRIPT LANGUAGE="JavaScript">



<!-- Begin
showImage();
//  End -->
</script>

<p><center>
<font face="arial, helvetica" size"-2">Free JavaScripts provided<br>
Master</font>
</center><p>

这篇关于显示文件夹中的随机图像,而不重复使用JS或PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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