1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Displaying images based on list of file types?

Discussion in 'PHP' started by Ty44ler, Jun 3, 2009.

  1. Ty44ler

    Ty44ler New Member

    Joined:
    Jun 3, 2009
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    What I'm trying to do:
    I am calling a list of file names from a folder and I'm trying to display a little icon next to it based on it's file type. Also I'm calling sub-folder names and trying to display an image of a folder next to that.

    What is going wrong:
    None of my images are showing up next to the file that is called. Also, folders are listed but the folder icon is not displayed next to it.

    Any ideas? I'm really new to this, so if you could explain things like you would to a small child that would be great. Thanks!

    Code:
    <?php
    $ignore = array(".","..","FTPCss.css","images","Thumbs.db");
     
    $fileImage = array(
       'pdf' => 'images/Adobe_PDF_icon.png',
       'jpg' => 'images/jpeg_icon.jpeg');
     
    while(false != ($file = readdir($dir))){
       if(!in_array($file,$ignore)){
          if(is_dir($file))
          {
             echo ("<p><a href=\"$file\"> <img src='images/folder.jpeg' /> $file</a> </p>");
          }else{
             $FileParts = explode(',',$file);
             $FileExtension = strtolower($FileParts[count($FileParts) - 1]);
             echo("<p><a href=\"$file\">".(isset($fileImage[$FileExtension]) ? "<img src='".$fileImage[$FileExtension]."' />" : "<img src='unknown.gif' />")." $file</a> </p>");
          }
       }
    }
    ?>
     
     
  2. Ty44ler

    Ty44ler New Member

    Joined:
    Jun 3, 2009
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    I just checked the output code... all the images are coming up as unknown...

    Why is that?
     

Share This Page