随机flash对象页面PHP

时间:2013-07-30 17:21:45

标签: php flash web

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的新手。 如果你可以尝试而不是因为做一些愚蠢的事情而对我大吼大叫,这可能是发生的事情。

2 个答案:

答案 0 :(得分: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();

答案 1 :(得分:1)

flash对象返回404。

其中一个确实有效。

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

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

也许这可能会更好。

$img_folder = "./files/flash/";