FIXED!
Feel free to use my code, no need to cite my work. There was no problem, just that the image size was too small and some weren't showing up. duh.
I will change the size from 100px to 500px for anyone who wants to use this code.
Have fun
我正在尝试使用互联网上可用的一些开放代码来制作随机闪存生成器。
原始代码:
<?php
$imglist='';
//$img_folder is the variable that holds the path to the swf files.
// see that you dont forget about the "/" at the end
$img_folder = "images/";
mt_srand((double)microtime()*1000);
//use the directory class
$imgs = dir($img_folder);
//read all files from the directory, ad them to a list
while ($file = $imgs->read()) {
if (eregi("swf", $file))
$imglist .= "$file ";
} closedir($imgs->handle);
//put all images into an array
$imglist = explode(" ", $imglist);
$no = sizeof($imglist)-2;
//generate a random number between 0 and the number of images
$random = mt_rand(0, $no);
$image = $imglist[$random];
//display random swf
echo '<embed src="'.$img_folder.$image.'" quality="high"
pluginspage="http://www.macromedia.com/go/getflashplayer"
type="application/x-shockwave-flash" width="100"
height="100"></embed>';
?>
我修改的代码:
<?php
$imglist='';
//$img_folder is the variable that holds the path to the swf files.
// see that you dont forget about the "/" at the end
$img_folder = "../files/flash/";
mt_srand((double)microtime()*1000);
//use the directory class
$imgs = dir($img_folder);
//read all files from the directory, ad them to a list
while ($file = $imgs->read()) {
if (preg_match("/(swf)/i", $file))
$imglist .= "$file ";
} closedir($imgs->handle);
//put all images into an array
$imglist = explode(" ", $imglist);
$no = sizeof($imglist)-2;
//generate a random number between 0 and the number of images
$random = mt_rand(0, $no);
$image = $imglist[$random];
//display random swf
echo '<embed src="'.$img_folder.$image.'" quality="high"
pluginspage="http://www.macromedia.com/go/getflashplayer"
type="application/x-shockwave-flash" width="500"
height="500"></embed>';
?>
起初,我在 11 行的 ergi 上遇到了问题,我被告知用 preg 替换它,我通过并弄清楚了这一点。
我加载了我的随机页面,(http://www.nsgaming.us/random/(,它闪烁了几分之一秒,我在文件夹中的随机闪光对象,但现在它什么也没显示。
请帮忙?
我的索引显示如下:
<html>
<head>
<title>test</title>
<?php
include("../menu.php");
include_once('random2.php');
?>
</head>
<body>
<p>This is the random page.</p>
<p>I am planning on having random flash objects load here but still working on it.</p>
</body>
</html>
请记住,我是网页设计,HTML和PHP的新手。如果你能试着不对我大喊大叫,因为我做了一些愚蠢的事情,这可能就是发生的事情。
而不是
if (preg_match("/(swf)/i", $file))
尝试
if (preg_match("/'.swf$/i", $file))
此外,如果文件名中有空格,则以下行将破坏您的代码。
$imglist = explode(" ", $imglist);
而不是
while ($file = $imgs->read()) {
if (preg_match("/(swf)/i", $file))
$imglist .= "$file ";
} closedir($imgs->handle);
//put all images into an array
$imglist = explode(" ", $imglist);
以下代码还将帮助您提供带有空格的文件名。这也将排除两个点目录。
$imglist=array();
while (false !== ($file = $imgs->read())) {
if (($file==".")||($file=="..")) continue;
if (preg_match("/'.swf$/i", $file))
$imglist[]= $file;
} $imgs->close();
闪光对象返回 404。
其中一个实际上有效。
http://www.nsgaming.us/files/flash/anon_partyhard007.swf
基于此,我认为您可能查看了错误的文件夹。我假设您有一个公共文件夹,然后是一个比根低一级的文件夹?
也许这可能会更好。
$img_folder = "./files/flash/";