Automatically create hyperlinks of all files in a folder

I have a lot of PDF’s and I want to automatically link to them from a webpage. Does anyone know a quick way to automatically create hyperlinks on a webpage from the folder (full of PDF’s).

tom12gaAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Eddie ShipmanAll-around developerCommented:
You have to create a server-side script to do that.
This is how to do it using PHP:

<?php
// change the path_to_pdf_dir to your directory...
if ($handle = opendir('path_to_pdf_dir')) {
  echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">';
  echo "<html>";
  echo "  <head>";
  echo "    <title>PDF List</title>";
  echo "  </head>";
  echo "  <body>";
  /* This is the correct way to loop over the directory. */
  while (false !== ($file = readdir($handle))) {
      if ($file != '.' && $file != '..' ) {
      echo "<a href=\"".$file."\">".$file."</a><br />";
      }
  }
  closedir($handle);
}
echo "  </body>";
echo "</html>";
?>

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rangasumanCommented:
If you are looking for a Javascript solution you can try to use JS ActiveX extensions

document.write("Contents of " + getCurrentFolder());

fileName = findFirstFile("*.pdf");
while(fileName.length)
{
    document.write("<a href=" + fileName + ">" + fileName + "</a>");
    fileName = findNextFile();
}
TheMegaLoserCommented:
This is how you do it in ASP. Of course you change the path in the fs.GetFolder to reflect the folder you want to use:

--- Example start ---
<html><head><title>PDF List</title></head>
<body>
<%
dim fs,fo,x
set fs=Server.CreateObject("Scripting.FileSystemObject")
set fo=fs.GetFolder("c:\")

for each x in fo.files
  'Print the name and size of all files in the test folder
  Response.write(x.Name & " (" & CLng(x.Size / 1024) & "kb) <br />")
next

set fo=nothing
set fs=nothing
%>
</body>
</html>
--- Example end  ---

You can also see this question for some more information: http://www.experts-exchange.com/Web/Q_21782165.html
Become a Microsoft Certified Solutions Expert

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

Shalom CarmelCTOCommented:
Alternatively, allow directory browsing in IIS or turn Indexing on in Apache.
This will automatically display a list of documents.

See example here: http://www.venera.com/downloads



ShalomC
tom12gaAuthor Commented:
Thanks for all the info. The PHP code works pretty well but it was looking in the root for the links not the folder. Easy fix.
Eddie ShipmanAll-around developerCommented:
Did you see this comment?
"// change the path_to_pdf_dir to your directory..."
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Development

From novice to tech pro — start learning today.