Zend - The PHP Company




HTML

Add Code


Auto-Generate a listing of Favorites/Bookmarks  

Type: code fragment
Added by: cseibert
Entered: 15/11/2000
Last modified: 01/12/2000
Rating: - (fewer than 3 votes)
Views: 5676
Auto-Generates a listing of you Bookmarks, great for anyone who runs a personal webserver and has a homepage in need of some active content. It will go recursively through your favorites folder, and create a page of links. The folder must be accessable via the server rights or php won't find it. You may want to make a mirror folder of you favorites inside a secure directory. Formatting is up to you, right now it just indents correctly.


<?php

/*     
    Code Written By Chase Seibert 11/14/2000, cseibert@bu.edu
    http://www.cyberts.com/CHASE/
    
    Auto-Generates a listing of you Bookmarks, great for anyone who runs a 
    personal webserver and has a homepage in need of some active content.

    It will go recursively through your favorites folder, and create a page
    of links.

    The folder must be accessable via the server rights or php won't find it.
    You may want to make a mirror folder of you favorites inside a secure 
    directory.

    Formatting is up to you, right now it just indents correctly.

   UPDATE: I reveiced a bug report from Mael Rieussec, which he was also kind enough to fix.

*/

$favorites_folder="C:My DocumentsFavorites";

function 
get_bookmarks($dir_name$indent){

 
$d dir($dir_name); // declares a dir variable from folder name

 
chdir($dir_name); // changes local working directory on server

 
while($entry=$d->read()){ // while there are still files left...

  
if (filetype($entry)=="file" && $entry!="Desktop.ini" && $entry!="Hotline Severs.lnk"){
        
// if these are files (not folders), and excepting hardcoded exceptions

  
$fd fopen ("$entry""r"); // open for read

  
while (!feof ($fd)) { // while not end of file
  
    
$buffer fgets($fd4096); // read a line

    
if ($buffer[0]=='U'){ // looking for the line that starts w/ "URL="
 
    
$buffer substr($buffer4); // returns everything after URL= 

    
for ($i=0;$i<$indent;$i++) echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"// prints indent
    
echo "<A HREF="".$buffer."">"// prints link

    
}
    
  }

  
$entry substr($entry0strlen($entry)-4); // cuts off .url at the end of filename
  
echo $entry."<br>n"."</A>"// prints filename and ends href tag

  
fclose ($fd); // closes file, otherwise major ass errors...
      
 
} else if (filetype($entry)=="dir" && $entry!="." && $entry!=".."){ // if it's a dir

        
for ($i=0;$i<$indent;$i++) echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"// indent again
    
echo "<B>".$entry."</B><br>n"// print folder name, in BOLD

    
get_bookmarks($entry$indent+1); // recursively call that directory

    //chdir($dir_name); // gotta change that dir back, not really sure why...

    
chdir(".."); // multi-nested dir bug fix by Mael Rieussec

   
}

 }

 
$d->close(); // close directory, once again to avoid file errors.

// end of get_bookmarks()

// Main Function

    
get_bookmarks($favorites_folder,0); // number is initial indent

?>


Usage Example




Rate This Script





Search



This Category All Categories