HTML
|
|
|
|
<?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($fd, 4096); // read a line
if ($buffer[0]=='U'){ // looking for the line that starts w/ "URL="
$buffer = substr($buffer, 4); // returns everything after URL=
for ($i=0;$i<$indent;$i++) echo " "; // prints indent
echo "<A HREF="".$buffer."">"; // prints link
}
}
$entry = substr($entry, 0, strlen($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 " "; // 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
|
|
|
|