<div dir="ltr">Hello,<div><br></div><div>why not create a view of random nodes. create a block display for the view and place it in a region at the top of your page?</div><div><br></div><div>Idan<br><br><div class="gmail_quote">
On Fri, Feb 25, 2011 at 9:23 AM, Austin Einter <span dir="ltr"><<a href="mailto:austin.einter@gmail.com">austin.einter@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div>Hi All</div>
<div>I would like to show image files (in a random manner) at the top of webpage.</div>
<div>I want to have a folder that contains all the image files.</div>
<div> </div>
<div>Then I want to have a separate php file (say rotate.php) having logic of selecting the random image file.</div>
<div>And want to include that rotate.php file from page.tpl.php.</div>
<div> </div>
<div>To start with, I followed the marinelli view.</div>
<div>Used the images and rotate.php (\marinelli\img\banners\rotate.php).</div>
<div> </div>
<div>Copied to image files and rotate.php to path where my page.tpl.php is present. </div>
<div> </div>
<div>In page.tpl.php, I added the line include ("rotate.php");</div>
<div> </div>
<div>The rotate.php looks as below. On debugging looks <em><font color="#ff0000">preg_match </font></em>line it breaks.<br>Please let me know why line "if ( preg_match( $regex, $file ) ) {" breaks.</div>
<div> </div>
<div>Regards</div>
<div>Austin</div>
<div><span lang="EN">
<p><em><?php</em></p>
<p><em>/**</em></p>
<p><em>* randomly select an image from the current directory and return it</em></p>
<p><em>*</em></p>
<p><em>* @todo - consider accepting a local path as $_GET['img'] for overrides</em></p>
<p><em>* to remain compatible with Marinelli's rotate.php</em></p>
<p><em>* </em></p>
<p><em>* (but why? why possible use case is there for linking to </em></p>
<p><em>* rotate.php?img=file.gif instead of straight to file.gif?)</em></p>
<p><em>*/</em></p>
<p><em>$file_types = array( </em></p>
<p><em>'gif' => 'image/gif',</em></p>
<p><em>'jpg' => 'image/jpeg',</em></p>
<p><em>'jpeg' => 'image/jpeg',</em></p>
<p><em>'png' => 'image/png'</em></p>
<p><em>) ;</em></p>
<p><em>$regex = '/\.(' . implode('|',array_keys($file_types)) . ')$/i' ;</em></p>
<p><em>$files = array() ;</em></p>
<p><em>$directory = opendir(".");</em></p>
<p><em>while ( FALSE !== ($file = readdir( $directory )) ) {</em></p>
<p><em><font color="#ff0000">if ( preg_match( $regex, $file ) ) {</font></em></p>
<p><em>$files[] = $file ;</em></p>
<p><em>}</em></p>
<p><em>}</em></p>
<p><em>if ( !empty( $files ) ) {</em></p>
<p><em>$which = rand(0,sizeof($files)-1) ;</em></p>
<p><em>if ( $file = file_get_contents( $files[$which] ) ) {</em></p>
<p><em>$parts = explode('.',$files[$which]) ;</em></p>
<p><em>$ext = strtolower($parts[sizeof($parts)-1]) ;</em></p>
<p><em></em></p>
<p><em>header( "Content-type: " . $file_types[$ext] ) ;</em></p>
<p><em>header( "Expires: Wed, 29 Jan 1975 04:15:00 GMT" );</em></p>
<p><em>header( "Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT" );</em></p>
<p><em>header( "Cache-Control: no-cache, must-revalidate" );</em></p>
<p><em>header( "Pragma: no-cache" );</em></p>
<p><em>print $file ;</em></p>
<p><em></em></p>
<p><em>}</em></p>
<p><em>}</em></p></span></div>
<br>--<br>
[ Drupal support list | <a href="http://lists.drupal.org/" target="_blank">http://lists.drupal.org/</a> ]<br></blockquote></div><br></div></div>