Echo filename without file extension

my focus is toward the top of the code. im trying to list all of my files in a folder (.txt files), but without the “.txt”, and echo them out as links. Can anyone help me revise my code? you can see it in action at http://americanliterature.hebronix.com/episodes.php. the different episodes are linked by ID in the url. and the text files contain the info. i realized i would rather use mysql, but i am really tired and have been working on this for a while. sorry if this doesnt make sense, i am really really tired.

<?php include('header.php'); 


//define the path as relative
$path = "/home/roche/americanliterature.hebronix.com/moviedata";

//using the opendir function
$dir_handle = @opendir($path) or die("Unable to open $path");

// strip txt from name an assign it as the key value
$find = ".txt";
$pos = strpos($file, $find);
$keyval = substr($file, 0, $pos);

echo "<span class='small'>Episodes:</span> ";

//running the while loop
while ($file = readdir($dir_handle)) 
{
   if($file!="." && $file!="..")
      echo "<a href='episodes.php?id=$file' class='small'>$file</a>, ";
}

//closing the directory
closedir($dir_handle);


if (isset($HTTP_GET_VARS['id']))
			{
				if ($HTTP_GET_VARS['id'] != '')
				{
		
		$filename = "./moviedata/" . $_GET['id'] . ".txt";
		$fp = fopen($filename,'r') or die("Please Select An Episode");
		$contents = fread($fp, filesize($filename));
		fclose($fp);
		
		$contents = trim($contents);
		$data = explode("|", $contents);

	   echo "<table width='558' cellpadding='0' cellspacing='0' background='images/episodebg.gif'>
<tr><td width='558' height='40' background='images/episodetop.gif'><img src='images/ep
" . $_GET['id'] . "
.gif'></td></tr>

<tr><td>
 <table cellpadding='0' cellspacing='0' width='100%' height='100%'>
  <tr valign='top'>
   <td><img src='images/left.gif'><img src='images/photo.gif'></td>

   <td><img src='images/viewtrailer.gif' border='0'><img src='images/dotdot.gif'><img src='images/download.gif' border='0'><img src='images/rightcorner.gif'><br><br>
       <img src='images/featuring.gif'><br>
       <table><td width='7'></td><td width='380'>
" . $data[0] . "
</td></table><br>
       <img src='images/description.gif'><br>
       <table><td width='7'></td><td width='380'>
" . $data[1] . "
</td></table></td>
  </tr>
 </table>
</td></tr>

<tr><td><img src='images/episodebottom.gif'></td></tr>
</table>";

 } else {
		echo "<br>Please Select An Episode";
	}
}

include('footer.php'); ?>