Zend - The PHP Company




Miscellaneous

Add Code


preform.php  

Type: code fragment
Added by: gleghorn
Entered: 06/03/2001
Last modified: 03/12/2000
Rating: - (fewer than 3 votes)
Views: 3939
I use this to make my windows 2000 Internet explorer bookmarks available from a webpage. This code is very basic and will require modification to be of use elsewhere (I make specific references to my filesystem layout). The linux box mounts two w2k drives as /mnt/gleghorn/khome and /mnt/gleghorn/favs, a miscellaneous area and my MSIE bookmarks respectively. The code refers to preform.phps. This is just a symbolic link to preform.php I specify preform.php as the last in the apache DirectoryIndex list, followed by index.html, default.html etc. When browsing either of the two mounted drives, if invoked by the absence of anything else indexy, it scans the directories and pretty-prints what it finds. Any MSIE-style *.url files are written out human-readable and clickable. hash include standard disclaimer


<?
  
// preform.php
  // by philip_gleghorn@yahoo.co.uk
  //
  // scan a directory specified in the $REQUEST_URI
  // show all directories as self-named hyperlinks
  // show all MSIE style *.url files as hyperlinks named by url destination
  // show all other files as self-named hyperlinks
  //
  // isort function by richard.heyes@heyes-computing.net
  // obtained from www.zend.com

  
function isort($a,$b){ 
    if(
ord(substr(strtolower($a),0,1)) == ord(substr(strtolower($b),0,1))) return 0
    return (
ord(substr(strtolower($a),0,1)) < ord(substr(strtolower($b),0,1))) ? -1
  }

  
$request urldecode($REQUEST_URI);
  
// we have to chdir else filetype() and filesize() (and friends) will fail
  //
  
chdir("/mnt$request");
  echo 
"<table width="100%"><tr width="100%"><td>Viewing /mnt" $request "</td><td align="right"><a href="/preform.phps">preform.php</a></td></tr></table>";
  
$handle=opendir("/mnt${request}"); 
  
$dirs_array = array();
  
$urls_array = array();
  
$other_array = array();
  while (
$file readdir($handle)) { 
    if (
filetype($file) == "dir") {
      
$dirs_array[] = $file;
    } else {
      
$pos strpos ($file".url");
      if (
$pos == 0) {
        
$others_array[] = $file;
      } else {
        
$urls_array[] = $file;
      }
    }
  }

  
closedir($handle); 

  if (
count($dirs_array) > 0) {
    
usort($dirs_array'isort');
    
reset($dirs_array);
    echo 
"<table border=0>";
    foreach(
$dirs_array as $myval) {
      
$mylink="/";
      if ((
$myval == "..") && (($request=="/gleghorn/favs/") || ($request=="/gleghorn/khome/"))) {
        
$mylink="/";
      } else {
        
$mylink $myval;
      }
      echo 
"<tr bgcolor="#440000"><td><a href="$mylink">$myval</a></td></tr>";
    
}
    echo 
"</table><p>";
  }

  if (
count($urls_array) > 0) {
    
usort($urls_array'isort');
    
reset($urls_array);
    echo 
"<table border=0>";
    foreach(
$urls_array as $myval) {
      
$farr file("/mnt$request$myval");
      
$furl $farr[1];
      
$ftok strtok ($furl'=');
      
$ftok strtok ('=');
      
$ftok substr($ftok0strlen($ftok)-2);
      echo 
"<tr bgcolor="#004400"><td>" . substr($myval, 0, strlen($myval)-4) . "</td><td><a href="$ftok">$ftok</a></td></tr>";
    
}
    echo 
"</table><p>";
  }

  if (
count($others_array) > 0) {
    
usort($others_array'isort');
    
reset($others_array);
    echo 
"<table border=0>";
    foreach(
$others_array as $myval) {
      
$mylink="/";
      if ((
$myval == "..") && (($request=="/gleghorn/favs/") || ($request=="/gleghorn/khome/"))) {
        
$mylink="/";
      } else {
        
$mylink $myval;
      }
      echo 
"<tr bgcolor="#000044"><td><a href="$myval">$myval</a></td><td>" . filesize($myval) . "</td><td>bytes</td></tr>";
    
}
    echo 
"</table><br>";
  }
  echo 
"n<!-- automatically generated by preform.php, Phil Gleghorn <philip_gleghorn@yahoo.co.uk> -->";

?>


Usage Example




Rate This Script





Search



This Category All Categories