note 88729 added to function.scandir

From: Date: Wed, 04 Feb 2009 23:11:46 +0000
Subject: note 88729 added to function.scandir
Groups: php.notes 
Request: Send a blank email to php-notes+get-150236@lists.php.net to get a copy of this message
Here's a simple little scandir() function that can pick a random photo (jpg only so far) and dislpay it. This also goes through an exclusion list and doesn't store anything you don't want to display. Use as you wish <?php $dir=scandir("photos"); $exclude=array("photos/.","photos/..","photos/ex"); $photos=array(); for ($x=0; $x<count($dir); $x++){ $dir[$x]="photos/".$dir[$x]; if (is_dir($dir[$x]) && !in_array($dir[$x], $exclude)){ $thisfolder=scandir($dir[$x]); for ($f=0; $f<count($thisfolder); $f++) if (strpos(strtolower($thisfolder[$f]), ".jpg")) $photos[]=$dir[$x]."/".$thisfolder[$f]; } } $rand=rand(0, count($photos)); echo "<div style='text-align: center;'>"; echo "<img src='".$photos[$rand]."' alt='' style='width: 80%'/>"; echo "</div>"; ?> ---- Server IP: 208.69.120.35 Probable Submitter: 152.30.57.113 ---- Manual Page -- http://www.php.net/manual/en/function.scandir.php Edit -- https://master.php.net/note/edit/88729 Del: integrated -- https://master.php.net/note/delete/88729/integrated Del: useless -- https://master.php.net/note/delete/88729/useless Del: bad code -- https://master.php.net/note/delete/88729/bad+code Del: spam -- https://master.php.net/note/delete/88729/spam Del: non-english -- https://master.php.net/note/delete/88729/non-english Del: in docs -- https://master.php.net/note/delete/88729/in+docs Del: other reasons-- https://master.php.net/note/delete/88729 Reject -- https://master.php.net/note/reject/88729 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#150236) next »