• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 476
  • Last Modified:

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).

0
tom12ga
Asked:
tom12ga
1 Solution
 
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>";
?>
0
 
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();
}
0
 
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
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
shalomcCommented:
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
0
 
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.
0
 
Eddie ShipmanAll-around developerCommented:
Did you see this comment?
"// change the path_to_pdf_dir to your directory..."
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now