Hi everyone,
Just signed up this forum, great to see so many active posts with replies!
Anyway, straight into the coding issue and I would be very gratetful for your help....
I am displaying a list of PDF files from a folder using an array.
Currently the output on the web page looks something like this:
<a href='test/A.pdf'>A.pdf</a>
<a href='test/B.pdf'>B.pdf</a>
But the output should be like this (without displaying file extension on the web page) :
<a href='test/A.pdf'>A</a>
<a href='test/B.pdf'>B</a>
I have tried a number of ways to prevent the file extension from displaying on the web page, but no matter what I try the file extension keeps appearing
I would really appreciate some help on this
Here is my full PHP code:
//get folder name from query string
$str_subcat = $_GET['subcat'];
$Folder = "pdfs/$str_subcat/";
$narray=array();
$i=0;
// Open the folder
$DirHandle = @opendir($Folder) or die($Folder." could not be opened.");
while($file = readdir($DirHandle))
{
if(is_dir($file))
{
continue;
}
//remove . and .. characters displayed by server.
//only display PDF files in the directory.
else if($file != '.' && $file != '..' && strpos($file, '.pdf'))
{
//echo "<a href='$path/$file'>$file</a><br/>";
$narray[$i]=$file;
$i++;
}
}
sort($narray);
for($i=0; $i<sizeof($narray); $i++)
{
echo "<tr>";
echo "<td width=100% class=bodycopy>";
echo "<a href='".$Folder.$narray[$i].$file."' target=blank>".$narray[$i].$file."</a>";
echo "</td>";
}
// Close the handle to the directory
closedir($DirHandle);