Online Shopping : Computers : Programming : Languages : PHP

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

28 of 43 people (65%) answered Yes
Recently 5 of 10 people (50%) answered Yes

Entry

How to READ a directory of PDF files that display as links to open the pdf

Nov 22nd, 2008 01:34
John Martin, games games, dman, Chris Carlton, Ken Freeman, http://www.ttnr.org


<?php
#######################################################################
#######
  # Project : Reading and Linking to files in specified 
directories            #
  # Name    : Chris 
Carlton                                                    #
  # Email   : 
[email protected]                                      #
  # Date    : Sept 3, 
2002                                                     #
  # Comments: This script will read a directory for a particular file 
type and #
  #           generate links to the files themselves. It will also 
display the #
  #           the file size to inform 
users.                                   #
#######################################################################
#######
  # SET THIS TO YOUR PDF DIRECTORY...
  $TheDirectory 
=  "/var/www/html/scripts/files/";
  # SET THIS TO THE EXTENSION OF FILE YOU WANT TO LIST AND LINK TO
  $TheFileType = "pdf";
  # YOU CAN SET THIS TO POINT DIRECTLY AT THE FILES OTHERWISE THE 
SCRIPT WILL GENERATE THE LINK FOR YOU
  #$LinkTo 
= "http://www.your-domain-name.com/files/";
  function ListFiles($FileType, $Directory, $LinkTo = false) {
    # GLOBALISE WHERE WE ARE!
    GLOBAL $PHP_SELF;
    # Initialize temporary array for sorting.
    $DirectoryFiles = array();
    # Print current directory location.
    printf ("<h3>%s</h3>\n", $Directory);
    # Change to directory.
    chdir($Directory);
    # Open directory.
    $DirectoryHandle = @opendir($Directory) or die("The directory 
\"$Directory\" was not found.");
    # Loop through the directory entries.
    while($DirectoryEntry = readdir($DirectoryHandle)) {
      if ((is_dir($DirectoryEntry)) && ($DirectoryEntry != "..") && 
($DirectoryEntry != ".")) {
        # we don't want this but you could do something with it later 
on!!
      } elseif (($DirectoryEntry != "..") && ($DirectoryEntry != ".") 
&& (substr(strtolower($DirectoryEntry), strrpos($DirectoryEntry, ".")
+1))) {
        $DirectoryFiles[] = $DirectoryEntry;
      }
    }
    # Sort the directory files into alphabetical order before 
displaying.
    sort($DirectoryFiles);
    # Get the correct the file path by comparing the directory with 
the variable $PHP_SELF if $LinkTo is not set
    if (!$LinkTo) {
      $LinkTo = $HTTP_HOST . substr($Directory, strpos($Directory, 
substr($PHP_SELF, 0, strrpos($PHP_SELF, "/"))), strlen($Directory));
    }
    # Display all the files and links to them.
    if (count($DirectoryFiles) > 0) echo "<ul>\n";
    for ($idx=0; $idx < count($DirectoryFiles); $idx++) {
      printf ("<li><a href=\"%s%s\">%s</a> <small>[%sk]
</small></li>\n", $LinkTo, $DirectoryFiles[$idx], $DirectoryFiles
[$idx], round(filesize($Directory.$DirectoryFiles[$idx])/1000,0));
    }
    if (count($DirectoryFiles) > 0) echo "</ul>\n";
    # Close directory
    closedir($DirectoryHandle);
  }
  ListFiles($TheFileType, $TheDirectory, $LinkTo);
?>
http://www.webs4soft.com/Links4.htm
http://hotelsinindia.webs4soft.com/hotels-in-delhi.htm
http://indiatravel.webs4soft.com/Resources.htm
http://indianmovies.webs4soft.com/Kuch-Kuch-Hota-Hai.htm
http://real-estate.webs4soft.com/property-tips.htm
http://foodhealthcaretips.webs4soft.com/Resources.htm
http://www.websitecompanyindia.com/seo-Links.htm
http://www.websitecompanyindia.com/seo-Links.htm
http://indianjewelry.websitecompanyindia.com/dimond-ring.htm
http://www.bestindiaeducation.com/Link-Exchange.htm
http://bestjobconsultant.bestindiaeducation.com/PARTNERS.htm
http://eloctronicandmobilestore.bestindiaeducation.com/mobile-links.htm
http://easyloanservice.bestindiaeducation.com/Home-Insurance-Links.htm
http://www.rajhealthcenter.com/Cosmetic-Surgery.htm
http://creativebusinessgroup.rajhealthcenter.com/Business-Links.htm
http://onlinefreeinternetgames.rajhealthcenter.com/Games-Links.htm
http://top-beauty-tips.rajhealthcenter.com/Beauty-Links.htm
http://www.indiatourpoint.com/Travel-Links.htm
http://four-wheeler-buy-tips.indiatourpoint.com/Auto-Links.htm
http://watch-online-free-cricket-match.indiatourpoint.com/Sports-Links.htm
http://directory.indiatourpoint.com/
http://www.bestlifeindia.com/Resources1.htm
http://directory.bestlifeindia.com/
http://freeorkutscrapandsms.bestlifeindia.com/SMS-Links.htm
http://onlinegiftshop.bestlifeindia.com/Gift-Links.htm
http://www.freemusicpoint.com/Music-Links.htm
http://love-dating.freemusicpoint.com
http://online-art-presentation.freemusicpoint.com/
http://onlinefurnitureshop.freemusicpoint.com/