dongqu1783 2013-07-31 17:03 采纳率: 100%
浏览 48
已采纳

显示随机swf打开的链接

I'm new to PHP and this seems like I'm just asking for code but in reality I want to know how to implement a link along with the random selector.

My code:

<?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="650"
height="450"></embed>';
?>

This basically grabs a random flash file from my site's directory. Since it won't affect the URL bar, they won't be able to send something they like to someone (which is an unintentional security feature). I want them to be able to send a link or possibly direct click to download.

Also, I was thinking of as well as the random generator, to make a left and right arrow that they can scroll through all the .swf's in the chosen directory, if possible.

the site is www.nsgaming.us and it's the 'Random' button under the text logo.

  • 写回答

1条回答 默认 最新

  • dsc56927 2013-07-31 17:44
    关注

    What you are asking for is reading parameters from the URL so people can link their friends to this SWF embed, you can do that by using $_GET

    Look at this example I coded.

        $swfs = array();
    $swf_location = '../files/flash/';
    
    if($handle = opendir($swf_location)) {
        while(false !== ($entry = readdir($handle))) {
            if(strtolower(pathinfo($path, PATHINFO_EXTENSION)) == 'swf') {
                $swfs[] = $entry;
            }
        }
        closedir($handle);
    }
    
    if(isset($_GET['swf']) && in_array($_GET['swf'], $swfs)) {
        $swf = $_GET['swf'];
    } else {
        $swf = $swfs[rand(0, count($swfs))];
    }
    
    echo '<embed src="' . $swf_location . $swf . '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="650" height="450"></embed><br />Send this to a friend: <input type="text" value="http://yourwebsite.com/thisfilesname.php?swf=' . $swf . '" length="55">';
    

    You're previous script was very messy and did a lot of useless stuff, this is secure and faster

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用