{"id":2222,"date":"2004-08-12T18:00:26","date_gmt":"2004-08-12T18:00:26","guid":{"rendered":"http:\/\/www.soulhuntre.com\/items\/date\/2004\/08\/12\/php-directory-listing-for-html\/"},"modified":"2004-08-12T18:00:26","modified_gmt":"2004-08-12T18:00:26","slug":"php-directory-listing-for-html","status":"publish","type":"post","link":"http:\/\/legacyiamsenseiken.local\/2004\/08\/12\/php-directory-listing-for-html\/","title":{"rendered":"PHP directory listing for HTML…"},"content":{"rendered":"

Ever need to show the files in a directory to the web, but don’t want to turn indexing on? The following PHP (saved here on my blog but stolen from this usenet post<\/a>) does that.<\/p>\n

Use at your own risk.<\/p>\n

<\/p>\n

<?php
  
  \/\/create the html to display the selection page
  echo ‘<html>’;
  echo ‘<body>’;
  echo ‘<h1>Click on the backup file to save it to your PC.<\/h1>’;
  echo ‘<ul>’;
  
  
  \/\/open the data directory and read the names of all the files
  \/\/into a list to be displayed on the page
  $handle=opendir(‘\/www\/htdocs\/backups\/data\/’);
  while (false !== ($file = readdir($handle))){
        \/\/if the list returns . or .. skip the display step
        \/\/and continue looping
        if(($file == “.”) OR ($file == “..”)){continue;}
        \/\/print out the name of the file so that it can be
        \/\/selected for download
        echo ‘<li><a href=”\/tmaster\/backups\/data\/’.$file.'”>’.$file.'<\/a><\/li>’;
  }
  
  \/\/close the direcotry
  closedir($handle);
  
  echo ‘<\/ul>’;
  echo ‘<\/body>’;
  echo ‘<\/html>’;
  ?> <\/p>\n","protected":false},"excerpt":{"rendered":"

Ever need to show the files in a directory to the web, but don’t want to turn indexing on? The following PHP (saved here on my blog but stolen from this usenet post) does that. Use at your own risk.<\/p>\n","protected":false},"author":3,"featured_media":53157,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"aside","meta":{"footnotes":""},"categories":[278],"tags":[],"_links":{"self":[{"href":"http:\/\/legacyiamsenseiken.local\/wp-json\/wp\/v2\/posts\/2222"}],"collection":[{"href":"http:\/\/legacyiamsenseiken.local\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/legacyiamsenseiken.local\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/legacyiamsenseiken.local\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"http:\/\/legacyiamsenseiken.local\/wp-json\/wp\/v2\/comments?post=2222"}],"version-history":[{"count":0,"href":"http:\/\/legacyiamsenseiken.local\/wp-json\/wp\/v2\/posts\/2222\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/legacyiamsenseiken.local\/wp-json\/wp\/v2\/media\/53157"}],"wp:attachment":[{"href":"http:\/\/legacyiamsenseiken.local\/wp-json\/wp\/v2\/media?parent=2222"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/legacyiamsenseiken.local\/wp-json\/wp\/v2\/categories?post=2222"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/legacyiamsenseiken.local\/wp-json\/wp\/v2\/tags?post=2222"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}