oli22 Posted December 9, 2010 Share Posted December 9, 2010 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: Quote Link to comment Share on other sites More sharing options...
oli22 Posted December 9, 2010 Author Share Posted December 9, 2010 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... Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted December 9, 2010 Share Posted December 9, 2010 you are using the DirectoryIterator class improperly. http://php.net/manual/en/directoryiterator.construct.php Quote Link to comment Share on other sites More sharing options...
oli22 Posted December 9, 2010 Author Share Posted December 9, 2010 I will read some of that but i'm a newbee doing my best to wing it...why is the first code working and the second not???Is the first code bad also even if it works? Where's the bug, it all seems so similar Quote Link to comment Share on other sites More sharing options...
oli22 Posted December 9, 2010 Author Share Posted December 9, 2010 looking at it after taking a break i think i see some random code left in there, that should be changed... Quote Link to comment Share on other sites More sharing options...
oli22 Posted December 10, 2010 Author Share Posted December 10, 2010 Maybe i'm thinking about this all wrong... Any suggestions? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.