Jump to content

Need help with this short script


oli22

Recommended Posts

I am re-using a simple script that works good to get random files  from a folder to get embed codes into a jquery slider(to embed videos)to create a video slider/gallery( http://www.awkward.se/demo/showcase/).The reason for the embed is there will be 50 and more videos in gallery and that's bad for page weight/page load.

I have taken out the random element for this code because i just want videos to get embeded  when icons are clicked(the onclick is already set up with the jquery script-->no worry about that).

I have change a few things (in red) and i thought i would work, but i am really not sure how to make it work at this point???

 

I get this error message:

Fatal error: Cannot use object of type DirectoryIterator as array

The original random code to get files which works perfect:

 

<?php

function getRandomFile($path)

{

    $files = array();

 

    foreach( new DirectoryIterator($path) as $file )

    {

        if($file->isFile())

        {

            $files[] = $path . $file->getFilename();

        }

    }

 

    $i = array_rand($files);

    return $files[$i];

}

 

$path = "vids";

 

$file = getRandomFile($path);

 

$final= substr($file, 4);

 

?>

It inserts into the html like this:

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="280" height="210" id="FLVPlayer">

...

  <param name="FlashVars" value="&MM_ComponentVersion=1&skinName=Clear_Skin_2&streamName=vids/<?php echo ($final); ?>&autoPlay=false&autoRewind=false" />

  <param name="swfversion" value="8,0,0,0" />

...

 

 

I modified it like this to get files to embed in the jquery gallery(changed values in blue):

<?php

 

function getEmbedFile($path)

{

    $filesEmbed = array();

 

    foreach( new DirectoryIterator($path) as $filesEmbed )

    {

        if($filesEmbed->isFile())

        {

            $filesEmbed[] = $path . $filesEmbed->getFilename();

        }

    }

 

    $i = array_rand($filesEmbed);

    return $filesEmbed[$i];

}

 

$path = "thumbEmbed";

$filesEmbed = getEmbedFile($path);

?>

<div>

<?php  echo ($filesEmbed); ?>

It inserts into the html like this:

 

 

<div class="showcase-thumbnail" >

<img src="images/ShowcaseThumbs/video1.GIF" alt="01" width="55px" />

<div class="showcase-thumbnail-caption">Play video 1</div>

To give you a better idea this a pic of the jquery slider:

343j4ic.jpg

Link to comment
https://forums.phpfreaks.com/topic/221154-need-help-with-this-short-script/
Share on other sites

Sorry presentation error

 

It inserts into slider like this:

<div>

<?php  echo ($filesEmbed); ?>

<div class="showcase-thumbnail" >

<img src="images/ShowcaseThumbs/video1.GIF" alt="01" width="55px" />

<div class="showcase-thumbnail-caption">Play video 1</div>

<div class="showcase-thumbnail-cover"></div>

</div>

</div>"

Which is the div that defines the thumbs in slider...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.