note 71631 added to function.readdir

From: Date: Fri, 08 Dec 2006 20:11:25 +0000
Subject: note 71631 added to function.readdir
Groups: php.notes 
Request: Send a blank email to php-notes+get-120441@lists.php.net to get a copy of this message
This small snipet will list and sort files from a directory ! This script also will only show file types that you allow. To change the files types edit the $file_types array. <?php function file_type($file){ $path_chunks = explode("/", $file); $thefile = $path_chunks[count($path_chunks) - 1]; $dotpos = strrpos($thefile, "."); return strtolower(substr($thefile, $dotpos + 1)); } $path = "files/"; $file_types = array('jpeg', 'jpg', 'ico', 'png', 'gif', 'bmp', 'html'); $p = opendir($path); while (false !== ($filename = readdir($p))) { $files[] = $filename; } sort($files); foreach ($files as $file) { $extension = file_type($file); if($file != '.' && $file != '..' && array_search($extension, $file_types)){ $file_count++; echo '<a href="'.$path.$file.'">'.$file.'</a> <br/>'; } } ?> ---- Server IP: 64.71.164.2 Probable Submitter: 68.106.94.135 ---- Manual Page -- http://www.php.net/manual/en/function.readdir.php Edit -- https://master.php.net/note/edit/71631 Del: integrated -- https://master.php.net/note/delete/71631/integrated Del: useless -- https://master.php.net/note/delete/71631/useless Del: bad code -- https://master.php.net/note/delete/71631/bad+code Del: spam -- https://master.php.net/note/delete/71631/spam Del: non-english -- https://master.php.net/note/delete/71631/non-english Del: in docs -- https://master.php.net/note/delete/71631/in+docs Del: other reasons-- https://master.php.net/note/delete/71631 Reject -- https://master.php.net/note/reject/71631 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#120441) next »