note 65889 deleted from function.opendir by bjori

From: Date: Wed, 10 May 2006 00:57:08 +0000
Subject: note 65889 deleted from function.opendir by bjori
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-111009@lists.php.net to get a copy of this message
Note Submitter: oryan at zareste dot com Reason: useless ---- 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>

« previous php.notes (#111009) next »