jsschmitt Posted May 21, 2009 Share Posted May 21, 2009 Below is the code I am using to build a form. What I want to do is grab all the playlist files in the directory, but not their file extension. i.e. Grab playlist.php, but have it display as just playlist Any ideas? <?php /* $url = "http://www.anomymage.com/tests/do/music/"; */ $path = "playlists/"; print "<form method='post' action='index.php'>\n"; print "<SELECT NAME='playlist'>\n"; print "<OPTION SELECTED VALUE=''>Select a playlist</OPTION>\n"; $narray=array(); $dir_handle = @opendir($path) or die("Unable to open $path"); $i=0; while($file = readdir($dir_handle)) { if($file != '.' && $file != '..' ) { //echo "<a href='$path/$file'>$file</a>"; $narray[$i]=$file; $i++; } } sort($narray); for($i=0; $i<sizeof($narray); $i++) { echo "<option>".$narray[$i]."</option>\n"; } //closing the directory closedir($dir_handle); print "<input type='submit' value='>'>\n"; print "</form>\n"; ?> Link to comment https://forums.phpfreaks.com/topic/159101-solved-php-directory-without-file-extensions/ Share on other sites More sharing options...
gevans Posted May 21, 2009 Share Posted May 21, 2009 This may work for you. change this line - $narray[$i]=$file; to <?php list($narray[$i], ) = explode('.', $file); Link to comment https://forums.phpfreaks.com/topic/159101-solved-php-directory-without-file-extensions/#findComment-839059 Share on other sites More sharing options...
jsschmitt Posted May 21, 2009 Author Share Posted May 21, 2009 Thanks! Took what you had, and added it (instead of changing). The script calls the filename.ext to actually load the playlist. I forgot to mention that, but here is the code, incase someone else can use it: <?php /* $url = "http://www.anomymage.com/tests/do/music/"; */ $path = "playlists/"; print "<form method='post' action='index.php'>\n"; print "<SELECT NAME='playlist'>\n"; print "<OPTION SELECTED VALUE=''>Select a playlist</OPTION>\n"; $narray=array(); $dir_handle = @opendir($path) or die("Unable to open $path"); $i=0; while($file = readdir($dir_handle)) { if($file != '.' && $file != '..' ) { //echo "<a href='$path/$file'>$file</a>"; $narray[$i]=$file; list($narray1[$i], ) = explode('.', $file); $i++; } } sort($narray); for($i=0; $i<sizeof($narray); $i++) { echo "<option value='".$narray[$i]."'>".$narray1[$i]."</option>\n"; } //closing the directory closedir($dir_handle); print "<input type='submit' value='>'>\n"; print "</form>\n"; ?> Link to comment https://forums.phpfreaks.com/topic/159101-solved-php-directory-without-file-extensions/#findComment-839072 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.