ReGRRtion!

Reply

Join Date: Jul 2008
Posts: 148
Reputation: mschroeder is on a distinguished road 
Solved Threads: 25
mschroeder mschroeder is offline Offline
Junior Poster

Re: ReGRRtion!

 
0
  #11
Sep 18th, 2009
change that line to:
  1. $parts = explode('.',$file->getBasename());
  2. $extension = strtolower(end($parts));

apparently explode returns its value by reference.

Are . and .. showing? In my quick testing they didn't show up at all.
Last edited by mschroeder; Sep 18th, 2009 at 12:24 pm.
If you're question/problem is solved don't forget to mark the thread as Solved!

-- Code I post is usually but not always tested. If it is tested it will be against 5.2.11 or 5.3.0
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 69
Reputation: baudday is an unknown quantity at this point 
Solved Threads: 0
baudday baudday is offline Offline
Junior Poster in Training

Re: ReGRRtion!

 
0
  #12
Sep 18th, 2009
Yeah they're showing up several times actually scattered throughout the files.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 148
Reputation: mschroeder is on a distinguished road 
Solved Threads: 25
mschroeder mschroeder is offline Offline
Junior Poster

Re: ReGRRtion!

 
0
  #13
Sep 18th, 2009
I've now tested it on both linux (centos) and windows (xp) and both php 5.2.10 and php 5.3.0 and don't see the dot directories showing up.

  1. <?php
  2. error_reporting(E_ALL | E_STRICT);
  3.  
  4. $path = '/path/to/file';
  5.  
  6. $iterator = new RecursiveDirectoryIterator($path);
  7. $recurse = new RecursiveIteratorIterator($iterator, RecursiveIteratorIterator::SELF_FIRST);
  8. echo "<ul>\n";
  9. $x=0;
  10. foreach ( $recurse as $file)
  11. {
  12. $parts = explode('.',$file->getBasename());
  13. $extension = strtolower(end($parts));
  14.  
  15. if( $file->isDir() && !$recurse->isDot() )
  16. {
  17. echo "<li><b>{$file->getBasename()}</b></li>\n";
  18.  
  19. }
  20. else if( $file->isFile() && $extension == 'zip' )
  21. {
  22. //unlink($file->getPathname());
  23. }
  24. else if( $file->isFile() && ($extension == 'mp3' || $extension == 'mpa') )
  25. {
  26. echo "<li>
  27. <input type = \"checkbox\" name = \"file$x\" value = \"{$file->getBasename()}\" />
  28. <input type = \"hidden\" name = \"file".$x."_path\" value = \"{$file->getPathname()}\" />
  29. <a href=\"{$file->getPathname()}\">{$file->getBasename()}</a>
  30. </li>\n";
  31. }
  32. ++$x;
  33. }
  34. echo "</ul>";
If you're question/problem is solved don't forget to mark the thread as Solved!

-- Code I post is usually but not always tested. If it is tested it will be against 5.2.11 or 5.3.0
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 986
Reputation: ardav will become famous soon enough ardav will become famous soon enough 
Solved Threads: 128
ardav's Avatar
ardav ardav is offline Offline
Posting Shark

Re: ReGRRtion!

 
-1
  #14
Sep 18th, 2009
  1. $op = "<select name='opts' id='opts'>";
  2. $dir = new DirectoryIterator( '/www/test/' );
  3. foreach($dir as $file ){
  4. if(!$file->isDot() && !$file->isDir() && preg_match("/.mp3$/",$file->getFilename())) {
  5. $op .= "<option value='{$file->getFilename()}'>{$file->getFilename()}</option>";
  6. }
  7. }
  8. $op .= "<select>";
  9. echo $op;

The above should print out all mp3 files to a dropdown. If you want to include other extensions, just change the regex in the preg_match parameter. 9 lines - should be nice. Cannibalize to your needs (ul list, etc).
Last edited by ardav; Sep 18th, 2009 at 2:41 pm. Reason: doh!
"...the woods would be a very silent place if no birds sang except for the best"
All opinions count - unless you're a serial downvoter.
F'enw i yw Mr. Blaidd. Byddwch yn ofalus - dwi'n cnoi.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 69
Reputation: baudday is an unknown quantity at this point 
Solved Threads: 0
baudday baudday is offline Offline
Junior Poster in Training

Re: ReGRRtion!

 
0
  #15
Sep 18th, 2009
So that solved some of the dots. The problem comes in when I get to a 3rd/4th level directory, Music->Artist->Album->Disc1 for instance. Then the dots start showing up again.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 69
Reputation: baudday is an unknown quantity at this point 
Solved Threads: 0
baudday baudday is offline Offline
Junior Poster in Training

Re: ReGRRtion!

 
0
  #16
Sep 18th, 2009
OOPS! Forgot to change one small part to what mschroeder suggested. The dots are gone. Any ideas on the indentation?
Reply With Quote Quick reply to this message  
Reply

Message:



Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC