| | |
ReGRRtion!
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jul 2008
Posts: 148
Reputation:
Solved Threads: 25
change that line to:
apparently explode returns its value by reference.
Are . and .. showing? In my quick testing they didn't show up at all.
PHP Syntax (Toggle Plain Text)
$parts = explode('.',$file->getBasename()); $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
-- Code I post is usually but not always tested. If it is tested it will be against 5.2.11 or 5.3.0
•
•
Join Date: Jul 2008
Posts: 148
Reputation:
Solved Threads: 25
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.
PHP Syntax (Toggle Plain Text)
<?php error_reporting(E_ALL | E_STRICT); $path = '/path/to/file'; $iterator = new RecursiveDirectoryIterator($path); $recurse = new RecursiveIteratorIterator($iterator, RecursiveIteratorIterator::SELF_FIRST); echo "<ul>\n"; $x=0; foreach ( $recurse as $file) { $parts = explode('.',$file->getBasename()); $extension = strtolower(end($parts)); if( $file->isDir() && !$recurse->isDot() ) { echo "<li><b>{$file->getBasename()}</b></li>\n"; } else if( $file->isFile() && $extension == 'zip' ) { //unlink($file->getPathname()); } else if( $file->isFile() && ($extension == 'mp3' || $extension == 'mpa') ) { echo "<li> <input type = \"checkbox\" name = \"file$x\" value = \"{$file->getBasename()}\" /> <input type = \"hidden\" name = \"file".$x."_path\" value = \"{$file->getPathname()}\" /> <a href=\"{$file->getPathname()}\">{$file->getBasename()}</a> </li>\n"; } ++$x; } 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
-- Code I post is usually but not always tested. If it is tested it will be against 5.2.11 or 5.3.0
PHP Syntax (Toggle Plain Text)
$op = "<select name='opts' id='opts'>"; $dir = new DirectoryIterator( '/www/test/' ); foreach($dir as $file ){ if(!$file->isDot() && !$file->isDir() && preg_match("/.mp3$/",$file->getFilename())) { $op .= "<option value='{$file->getFilename()}'>{$file->getFilename()}</option>"; } } $op .= "<select>"; 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.
All opinions count - unless you're a serial downvoter.
F'enw i yw Mr. Blaidd. Byddwch yn ofalus - dwi'n cnoi.
![]() |
Other Threads in the PHP Forum
- Previous Thread: I need to embed stock live charts in website
- Next Thread: Quick foreach question
| Thread Tools | Search this Thread |
advanced apache api array beginner binary broken cakephp check checkbox class cms code cookies cron curl database date display dropdownlist dynamic echo email eregi error execution file files folder form forms function functions google head href htaccess html if...loop image include includingmysecondfileinthechain insert ip javascript job joomla jquery key library limit link login mail menu mlm multiple mysql oop paypal pdf pdfdownload php phpvotingscript problem query radio random recursion remote screen script search server sessions smarty sms soap sorting source space sql startup stored syntax system table traffic tutorial unicode update upload url validator variable video web xml youtube zend





