Hey all,
I found this script that i'm using to read a directory, show all the pdf files in it, then be able to click on one of the pdf files displayed and open the pdf. So far i can show the pdfs in the directory, but when I click on one, i get an error page. Can someone take a look at this and tell me what I'm doing wrong. I'm assuming that my browser is not seeing it as a .pdf file and doesn't know how to open it.
<?php
$current_dir = "$DOCUMENT_ROOT"."..//pdfs/"; //Put in second part, the directory - without a leading slash but with a trailing slash!
$dir = opendir($current_dir); // Open the sucker
echo ("<p><h1>List of available files:</h1></p><hr><br />");
while ($file = readdir($dir)) // while loop
{
$parts = explode(".", $file); // pull apart the name and dissect by period
if (is_array($parts) && count($parts) > 1) { // does the dissected array have more than one part
$extension = end($parts); // set to we can see last file extension
if ($extension == "pdf" OR $extension == "PDF") // is extension ext or EXT ?
echo "<a href=\"$file\" target=\"_blank\"> $file </a><br />"; // If so, echo it out else do nothing cos it's not what we want
}
}
echo "<hr><br />";
closedir($dir); // Close the directory after we are done
?>
Right now this is looking into a directory on my wwwroot folder because I can not get it to see any directories outside of my wwwroot folder. I'd like it to see files in a directory on a shared fileserver on my network if anyone can help with that, haven't been able to get it to work and my knowledge is not what it should be yet.
Thanks for any help.