note 65889 added to function.opendir

From: Date: Tue, 09 May 2006 21:53:27 +0000
Subject: note 65889 added to function.opendir
Groups: php.notes 
Request: Send a blank email to php-notes+get-110969@lists.php.net to get a copy of this message
I timed my shell_exec example and it really is slower than opendir. It's ideal if you want the directory sorted a certain way (I use it to sort by modification time) but opendir is the fastest. While I'm at it, here's a Javascript HTML/PHP to display all files in each directory from the directory of the script. You may want to keep users away from this if you have any files you want to hide, in which case, name it something like 'random.php' and ensure the users can't find this script. Clicking directory names will roll out the files in a table beneath them, and clicking the '()' beside directories takes you to the directory - <html> <head> <title>directory</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <script language="javascript" type="text/javascript"> <!-- function convert(thelayer){ if(document.getElementById){ result=document.getElementById(thelayer);} else if(document.all){ result=document.all[thelayer];} return result; } function addit(ayer){ tehlayer=convert(ayer); if(tehlayer.style.display=="none"){tehlayer.style.display="";} else{tehlayer.style.display="none";} } //--> </script> <style type="text/css"> <!-- table{ border:thin solid #000000; } //--> </style> </head><body><center> <?php $a=0; listd('.'); ?></center><?php function listd($dir){ global $a; $handle = opendir($dir); while (false !== ( $file = readdir($handle))){ if($file!=='.'&&$file!=='..'){ if(strpos($file,'.')===false){ echo '<a href="Javascript:;" onClick="addit(\''.$file.$a.'\');">'.$file.'</a> <a href="'.$dir.'/'.$file.'">()</a><br>'; ?><table id="<?php echo $file.$a;?>" name="<?php echo $file.$a;?>" style="display:none"><tr><td><?php listd($dir.'/'.$file);?></td></tr></table><?php } else{ echo '<a href="'.$dir.'/'.$file.'">'.$file.'</a><br>'; } } $a++; } closedir($handle); } ?> </body> </html> ---- Server IP: 64.71.164.2 Probable Submitter: 216.12.200.106 ---- X-Spam-Status: No, hits=3.7 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER, HTML_60_70,HTML_MESSAGE,HTML_TAG_BALANCE_A autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.opendir.php Edit -- http://master.php.net/note/edit/65889 Del: integrated -- http://master.php.net/note/delete/65889/integrated Del: useless -- http://master.php.net/note/delete/65889/useless Del: bad code -- http://master.php.net/note/delete/65889/bad+code Del: spam -- http://master.php.net/note/delete/65889/spam Del: non-english -- http://master.php.net/note/delete/65889/non-english Del: in docs -- http://master.php.net/note/delete/65889/in+docs Del: other reasons-- http://master.php.net/note/delete/65889 Reject -- http://master.php.net/note/reject/65889 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#110969) next »