Heb een opensource filemanager systeem gedownload. Bij de weergave van de bestanden wordt steeds hetzelfde icon-image gebruik, ongeacht het type bestand. Nu wil ik graag icon images koppelen aan extensies van de bestanden, echter ben echt net begonnen met php en heb niet echt een idee hoe ik nu verder moet. Heb wel alvast een lijst gemaakt betreffende de link van extensie en icon-plaatje. Echter weet dus niet hoe ik dit moet integreren in de bestaande file class. Onderstaand de 'class file' en de 'folder map types naar image icon'. Hoop dat jullie enig idee hebben, thx


class file {
  var $stat    = array();
  var $pathinfo    = array();
  var $name;
  var $path;
  var $dirname;
  var $basename;
  var $extension;
  var $size;
  var $size_h;
  var $read;
  var $write;
  var $execute;
  var $mime;
  
  ////
  //  function file
  //  (Constructor) Reads the rights and sets the default value for a file
  ////
  
  function file ($file) {
    $this->stat        = stat($file);
    $this->pathinfo    = pathinfo($file);
    $this->dirname    = $this->pathinfo["dirname"];
    $this->basename    = $this->pathinfo["basename"];
    $this->extension    = strtolower($this->pathinfo["extension"]);
    $this->size        = $this->stat[7];
    $this->uid        = $this->stat[4];
    $this->gid        = $this->stat[5];
    $this->date        = $this->stat[9];
    
    if (!ereg("/$", $this->dirname )) $this->dirname  .= "/";
    
    // Create a human readable file size
    if ($this->size < 1024)        $this->size_h = $this->size . " bytes";
    if ($this->size > 1024)        $this->size_h = round($this->size / 1024, 2) . " KB";
    if ($this->size > 1048576)        $this->size_h = round($this->size / 1048576, 2) . " MB";
    if ($this->size > 1073741824)    $this->size_h = round($this->size / 1073741824, 2) . " GB";
    
    $this->read    = false;
    $this->write   = false;
    $this->execute = false;
    if (is_readable($file))   $this->read = true;
    if (is_writable($file))   $this->write = true;
    if (is_executable($file)) $this->execute = true;
    clearstatcache();
    
    // aliasses
    $this->name = $this->basename;
    $this->path = $this->dirname;
    if (strlen($this->extension) > 10) $this->extension = "";
  }
  
  function get_mime() {
    $verify = TRUE;
    $fn = $this->dirname . $this->name;
    
    if (empty($fn)) {
      return "";
    }

    if ($verify) {
      if ($fp = @fopen($fn, "rb")) {
        $fcont = fread($fp, 32);
        fclose($fp);
      } else {
        return "";
      }
    }

    $ext = $this->extension;

    switch ($ext) {
      case "aif":
      case "aifc":
      case "aiff":
        return "audio/aiff";

      case "asp":
        return "text/asp";

      case "avi":
        return "video/avi" .
          (!$verify || (substr($fcont, 0, 4) == "RIFF") ? "" : "*");
          
      case "mpg":
      case "mpeg":
        return "video/mpeg";

      case "wmv":
        return "video/windows-media";

      case "bmp":
        return "image/bmp" .
          (!$verify || (substr($fcont, 0, 2) == "BM") ? "" : "*");

      case "css":
        return "text/css";

      case "doc":
        return "application/msword" .
          (!$verify ||
          (substr($fcont, 0, 8) == "\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1") ?
                 "" : "*");

      case "exe":
      case "dll":
      case "scr":
        return "application/x-msdownload" .
          (!$verify || (substr($fcont, 0, 2) == "MZ") ? "" : "*");

      case "hlp":
        return "application/windows-help" .
          (!$verify ||
          (substr($fcont, 0, 4) == "\x3F\x5F\x03\x00") ? "" : "*");

      case "htm":
      case "html":
        return "text/html" .
          (!$verify ||
          (substr($fcont, 0, 6) == "<html>") ||
          (substr($fcont, 0, 14) == "<!DOCTYPE HTML") ?
          "" : "*");

      case "gif":
        return "image/gif" .
          (!$verify || (substr($fcont, 0, 3) == "GIF") ? "" : "*");

      case "gz":
      case "tgz":
        return "application/x-gzip" .
          (!$verify || (substr($fcont, 0, 3) == "\x1F\x8B\x08") ? "" : "*");

      case "jfif":
      case "jpe":
      case "jpeg":
      case "jpg":
        return "image/jpeg" .
         (!$verify ||
         (substr($fcont, 0, 10) == "\xFF\xD8\xFF\xE0\x00\x10JFIF") ?
          "" : "*");

      case "mov":
        return "video/quicktime";

      case "pdf":
        return "application/pdf" .
          (!$verify || (substr($fcont, 0, 4) == "%PDF") ? "" : "*");

      case "php":
      case "php3":
      case "php4":
      case "phtml":
        return "application/x-httpd-php" .
          (!$verify || (substr($fcont, 0, 5) == "<?") ? "" : "*");

      case "pl":
        return "text/perl" .
          (!$verify ||
          (substr($fcont, 0, 21) == "#!/usr/local/bin/perl") ? "" : "*");

      case "png":
        return "image/x-png" .
          (!$verify || (substr($fcont, 0, 4) == "\x89PNG") ? "" : "*");

      case "psd":
        return "image/psd" .
          (!$verify || (substr($fcont, 0, 4) == "8BPS") ? "" : "*");

      case "tiff":
      case "tif":
        return "image/tiff" .
          (!$verify ||
          (substr($fcont, 0, 8) == "\x4D\x4D\x00\x2A\x00\x00\x00\x08") ||
          (substr($fcont, 0, 4) == "\x49\x49\x2A\x00") ?
          "" : "*");

      case "ttf":
        return "application/x-ttf";

      case "txt":
      case "ini":
      case "log":
      case "sql":
      case "cfg":
      case "conf":
      case "tpl":
        return "text/plain";

      case "swf":
        return "application/x-shockwave-flash";


      case "wav":
        return "audio/x-wav" .
          (!$verify || (substr($fcont, 0, 4) == "RIFF") ? "" : "*");

      case "wma":
        return "audio/x-ms-wma";
        
      case "mp3":
        return "audio/x-mp3";

      case "xml":
        return "text/xml" .
          (!$verify || (substr($fcont, 0, 5) == "<?xml") ? "" : "*");

      case "zip":
        return "application/x-zip-compressed" .
          (!$verify || (substr($fcont, 0, 2) == "PK") ? "" : "*");
    }
    return "";
  }
}



de lijst van folder map types naar image icon


# folder map types naar image icon
    map_type_to_icon {
    folder   = folder.png
    move_up  = move_up.png
    link     = mime.png
    unknown  = mime.png
    folder_denied = folder_denied.png
    file_denied   = mime_denied.png
    image1   = image.png
    image2   = draw.png
    video    = video.png
    sound    = sound.png
    archiv   = tar.png
    backup   = mime.png
    text     = txt.png
    html     = html.png
    xml      = html.png
    asm      = source.png
    c        = source.png
    cpp      = source.png
    cheader  = source.png
    css      = source.png
    java     = source.png
    jscript  = source.png
    latex    = source.png
    makefile = source.png
    modula2  = source.png
    mysql    = source.png
    pascal   = source.png
    perl     = source.png
    php      = source.png
    shellscript = source.png
    source   = source.png
    pdf      = pdf.png
    ps       = pdf.png
    virtools       = virtools.png
    doc       = doc.png
    presentation       = presentation.png
  }

  # map file types to file extensions
  map_type_to_ext {
    image1   = .gif|.jpg|.jpeg|.png
    image2   = .bmp|.tga|.psd|.psp
    video    = .avi|.mov|.mpg|.mpeg|.asf|.wmv|.qt|.mp4
    sound    = .mp3|.ogg|.wma|.wav|.au
    archiv   = .tar|.gz|.bz2|.rar|.zip|.z
    backup   = .bak|~
    text     = .txt|.asc
    html     = .htm|.html|.xml|.xsl
    xml      = .xml|.xsl
    asm      = .8|.a|.a86|.asm|.s
    c        = .c
    cpp      = .cpp|.c++
    cheader  = .h
    css      = .css
    java     = .j|.jav|.java
    jscript  = .js
    latex    = .latex|.dtx|.tex
    makefile = makefile
    modula2  = .m2|.mod
    mysql    = .sql
    pascal   = .pas
    perl     = .pl
    php      = .php|.php3|.php4|.phtml|.phtm|.phps
    shellscript = .sh
    source   = .pas|.mod
    pdf      = .pdf
    ps       = .ps
    virtools       = .vmo|.cmo
    doc       = .doc|.sxw|.rtf
    presentation       ]= .ppt|.pps|.sxi
  }
kan dit misschien werken?


if (ereg(".*\.jpg",$filename)) { $icon = "image1.jpg"; }
elseif (ereg(".*\.wmv",$filename)) { $icon = "image2.jpg"; }
elseif (ereg(".*\.doc",$filename)) { $icon = "image2.jpg"; }

Reageren