[support] How to show random image files in webpage

Austin Einter austin.einter at gmail.com
Fri Feb 25 11:33:02 UTC 2011


Thanks Idan
I have very limited knowledge on views. Know how to create simple views.

Can you give an overview how to make a view with random nodes.

I assume, in nodes we will be printing the images.

Regards,
Kamal



On Fri, Feb 25, 2011 at 1:10 PM, Idan Arbel <idan at arbel-designs.com> wrote:

> Hello,
>
> 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?
>
> Idan
>
>   On Fri, Feb 25, 2011 at 9:23 AM, Austin Einter <austin.einter at gmail.com>wrote:
>
>>   Hi All
>> I would like to show image files (in a random manner) at the top of
>> webpage.
>> I want to have a folder that contains all the image files.
>>
>> Then I want to have a separate php file (say rotate.php) having logic of
>> selecting the random image file.
>> And want to include that rotate.php file from page.tpl.php.
>>
>> To start with, I followed the marinelli view.
>> Used the images and rotate.php (\marinelli\img\banners\rotate.php).
>>
>> Copied to image files and rotate.php to path where my page.tpl.php is
>> present.
>>
>> In page.tpl.php, I added the line  include ("rotate.php");
>>
>> The rotate.php looks as below. On debugging looks *preg_match *line it
>> breaks.
>> Please let me know why line "if ( preg_match( $regex, $file ) ) {" breaks.
>>
>> Regards
>> Austin
>>
>> *<?php*
>>
>> */***
>>
>> ** randomly select an image from the current directory and return it*
>>
>> ***
>>
>> ** @todo - consider accepting a local path as $_GET['img'] for overrides*
>>
>> ** to remain compatible with Marinelli's rotate.php*
>>
>> ** *
>>
>> ** (but why? why possible use case is there for linking to *
>>
>> ** rotate.php?img=file.gif instead of straight to file.gif?)*
>>
>> **/*
>>
>> *$file_types = array( *
>>
>> *'gif' => 'image/gif',*
>>
>> *'jpg' => 'image/jpeg',*
>>
>> *'jpeg' => 'image/jpeg',*
>>
>> *'png' => 'image/png'*
>>
>> *) ;*
>>
>> *$regex = '/\.(' . implode('|',array_keys($file_types)) . ')$/i' ;*
>>
>> *$files = array() ;*
>>
>> *$directory = opendir(".");*
>>
>> *while ( FALSE !== ($file = readdir( $directory )) ) {*
>>
>> *if ( preg_match( $regex, $file ) ) {*
>>
>> *$files[] = $file ;*
>>
>> *}*
>>
>> *}*
>>
>> *if ( !empty( $files ) ) {*
>>
>> *$which = rand(0,sizeof($files)-1) ;*
>>
>> *if ( $file = file_get_contents( $files[$which] ) ) {*
>>
>> *$parts = explode('.',$files[$which]) ;*
>>
>> *$ext = strtolower($parts[sizeof($parts)-1]) ;*
>>
>> **
>>
>> *header( "Content-type: " . $file_types[$ext] ) ;*
>>
>> *header( "Expires: Wed, 29 Jan 1975 04:15:00 GMT" );*
>>
>> *header( "Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT" );*
>>
>> *header( "Cache-Control: no-cache, must-revalidate" );*
>>
>> *header( "Pragma: no-cache" );*
>>
>> *print $file ;*
>>
>> **
>>
>> *}*
>>
>> *}*
>>
>> --
>> [ Drupal support list | http://lists.drupal.org/ ]
>>
>
>
> --
> [ Drupal support list | http://lists.drupal.org/ ]
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/support/attachments/20110225/5580032e/attachment-0001.html 


More information about the support mailing list