0
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/),它闪烁了几分之一秒,这是我在文件夹中的一个随机 flash 对象,但现在它什么也没显示。

请帮忙?

我的索引显示如下:

    <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 方面的新手。如果你能试着不要因为我做了一些愚蠢的事情而对我大喊大叫,这可能就是发生了什么。

4

2 回答 2

2

代替

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();
于 2013-07-30T17:31:58.943 回答
1

Flash 对象返回 404。

其中之一确实有效。

http://www.nsgaming.us/files/flash/anon_partyhard007.swf

基于此,我认为您可能正在查看错误的文件夹。我假设您有一个公共文件夹,然后是根目录下一级的文件夹?

也许这可能会更好。

$img_folder = "./files/flash/";
于 2013-07-30T17:30:31.523 回答