Have downloaded an OS filemanager, however all listed files have the same image icon, independent of their file extension. So i made a list of image-icon to extension settings, and now i want to include this list into the 'class file', So that when the files are listed each filetype gets it's own icon imgae, depending on there file extension. But I have no clue how to do just that. Any suggestions / tips would be very welcome.

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 ""; 
  } 
}

map type to icon list

# map type to 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
  }

    Use ereg() function to matchup:

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

      ok, i used the ereg() function

      So what I had in my php file:

      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  .= "/";
      

      and this was set in my html tempate file, which defined the use the default image (file.jpg) for all extension types:

      <TD WIDTH='{$table_icon_width}' ALIGN='center'>   
      <IMG NAME='{$files[$key]->name|htmlspecialchars|stripslashes}' SRC='templates/blackdecember/images/file.jpg' BORDER='0'/> </TD>

      What is is exactly that i have to change in these two files inorder to relate an extension to a image-icon. Here is the list f extensions/icons:

      if (ereg(".*\.jpg",$name)) { $icon = "templates/blackdecember/icons/image.png"; }
      elseif (ereg(".*\.gif",$name)) { $icon = "templates/blackdecember/icons/image.png"; }
      elseif (ereg(".*\.jpeg",$name)) { $icon = "templates/blackdecember/icons/image.png"; }
      elseif (ereg(".*\.png",$name)) { $icon = "templates/blackdecember/icons/image.png"; }
      elseif (ereg(".*\.tif",$name)) { $icon = "templates/blackdecember/icons/draw.png"; }
      elseif (ereg(".*\.bmp",$name)) { $icon = "templates/blackdecember/icons/draw.png"; }
      elseif (ereg(".*\.tga",$name)) { $icon = "templates/blackdecember/icons/draw.png"; }
      elseif (ereg(".*\.psd",$name)) { $icon = "templates/blackdecember/icons/draw.png"; }
      elseif (ereg(".*\.psp",$name)) { $icon = "templates/blackdecember/icons/draw.png"; }
      elseif (ereg(".*\.avi",$name)) { $icon = "templates/blackdecember/icons/video.png"; }
      elseif (ereg(".*\.mov",$name)) { $icon = "templates/blackdecember/icons/video.png"; }
      elseif (ereg(".*\.mpg",$name)) { $icon = "templates/blackdecember/icons/video.png"; }
      elseif (ereg(".*\.mpeg",$name)) { $icon = "templates/blackdecember/icons/video.png"; }
      elseif (ereg(".*\.asf",$name)) { $icon = "templates/blackdecember/icons/video.png"; }
      elseif (ereg(".*\.wmv",$name)) { $icon = "templates/blackdecember/icons/video.png"; }
      elseif (ereg(".*\.qt",$name)) { $icon = "templates/blackdecember/icons/video.png"; }
      elseif (ereg(".*\.mp4",$name)) { $icon = "templates/blackdecember/icons/video.png"; }
      

      Thanks for helping, really appriciated it (cause what i've now learning is that by propramming a trial and error approach isn't rally that successful 😉 )

        Write a Reply...