Jump to content

[SOLVED] PHP Directory - without file extensions


jsschmitt

Recommended Posts

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";

	?>

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";

	?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.