Open Dir

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rpapaiof
    New Member
    • Oct 2006
    • 27

    Open Dir

    [php]
    <?php
    echo "<form method=post>";
    echo "<input type=text name=dirname>";
    echo "<input type=submit value='Show file' name=knopka>";
    echo "</form>";
    $d=opendir($_RE QUEST[dirname]);

    while (($str=readdir( $d)) != NULL ) {
    if ( is_dir("$_REQUE ST[dirname]".$str) ) {
    echo "<img src=folder.bmp> $str";
    }
    echo "<br>";
    }
    closedir($d);
    ?>[/php]
    Let's keep our posted code readable, PLEASE!!

    i have such program and i asigned a folder icon for folders how i must assign one for JPG file special jpg icon (windows Default)
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    Are you looking for the code to assign icons to specific file types or just for the jpg icon?

    Ronald :cool:

    Comment

    • rpapaiof
      New Member
      • Oct 2006
      • 27

      #3
      Originally posted by ronverdonk
      Are you looking for the code to assign icons to specific file types or just for the jpg icon?

      Ronald :cool:
      i want to assign JPG icon for JPG File ,Note pad Icon for txt file i have the icons i need to know how i must do it .
      i have tried is_file but can't use it in correct way.

      Comment

      • ronverdonk
        Recognized Expert Specialist
        • Jul 2006
        • 4259

        #4
        Here is a sample that reads the files in a directory and shows them in a table, preceeded by an image, depending on the file extension.[php]<?php
        $path = "mail/";
        $dir = dir($path);
        echo "<table border='0'>";
        while ($file=$dir->read() ) {
        if ($file != '.' && $file != '..') {
        if (!$icon = fileExt($file)) {
        $icon = "default.gi f";
        }
        echo "<tr><td><i mg src='$icon' border='0'></td><td>$file</td></tr>";
        }
        }
        echo '</table>';

        function fileExt($fn) {
        $f_ext = "";
        $fn=strtolower( $fn);
        ereg( ".*\.([a-zA-z0-9]{0,5})$", $fn, $regs ); // extract file extension
        $f_ext = $regs[1];
        switch ($f_ext)
        {
        case "jpg" : return "jpg.gif"; break;
        case "txt" : return "txt.gif"; break;
        case "png" : return "png.png"; break;
        case "php" : return "php.gif"; break;
        // do the rest yourself
        default : return "default.gi f"; break;
        }
        return false;
        }
        ?>[/php]
        Ronald :cool:

        Comment

        • TheMadMidget
          New Member
          • Oct 2006
          • 98

          #5
          How do you distinguish a folder?

          Comment

          • TheMadMidget
            New Member
            • Oct 2006
            • 98

            #6
            Nevermind, I finally found it. I used @is_dir()

            Multiple icons can be found here, note they are 16x16.
            Zipped image files

            Also here is the code for a full directory view with icons.
            [PHP]
            <?php
            $path = "../";
            $dir = dir($path);
            echo "<table border='0'>";
            while ($file=$dir->read() ) {
            if ($file != '.' && $file != '..') {
            $icon = fileExt($file, $path);
            echo "<tr><td>$i con</td><td>$file</td></tr>\n";
            }
            }
            echo '</table>';

            function fileExt($file, $path)
            //find the appropriate icon depending on the extension (returns a link to the image file)
            {
            ereg( ".*\.([a-zA-z0-9]{0,5})$", $file, $regs ); // extract file extension
            $ext = $regs[1];
            $icon_path='win xp';
            if ($icon_path == '')
            {
            return '';
            }
            if ($ext == '')
            {
            $icon = 'generic';
            if (@is_dir($path . $file))
            {
            $icon = 'dir';
            }
            }
            else
            {
            $icon = 'unknown';
            static $icon_types = array(
            'binary' => array('bat', 'bin', 'com', 'dmg', 'dms', 'exe', 'msi',
            'msp', 'pif', 'pyd', 'scr', 'so'),
            'binhex' => array('hqx'),
            'cd' => array('bwi', 'bws', 'bwt', 'ccd', 'cdi', 'cue', 'img',
            'iso', 'mdf', 'mds', 'nrg', 'nri', 'sub', 'vcd'),
            'comp' => array('cfg', 'conf', 'inf', 'ini', 'log', 'nfo', 'reg'),
            'compressed' => array('7z', 'a', 'ace', 'ain', 'alz', 'amg', 'arc',
            'ari', 'arj', 'bh', 'bz', 'bz2', 'cab', 'deb', 'dz', 'gz',
            'io', 'ish', 'lha', 'lzh', 'lzs', 'lzw', 'lzx', 'msx', 'pak',
            'rar', 'rpm', 'sar', 'sea', 'sit', 'taz', 'tbz', 'tbz2',
            'tgz', 'tz', 'tzb', 'uc2', 'xxe', 'yz', 'z', 'zip', 'zoo'),
            'dll' => array('386', 'db', 'dll', 'ocx', 'sdb', 'vxd'),
            'doc' => array('abw', 'ans', 'chm', 'cwk', 'dif', 'doc', 'dot',
            'mcw', 'msw', 'pdb', 'psw', 'rtf', 'rtx', 'sdw', 'stw', 'sxw',
            'vor', 'wk4', 'wkb', 'wpd', 'wps', 'wpw', 'wri', 'wsd'),
            'image' => array('adc', 'art', 'bmp', 'cgm', 'dib', 'gif', 'ico',
            'ief', 'jfif', 'jif', 'jp2', 'jpc', 'jpe', 'jpeg', 'jpg', 'jpx',
            'mng', 'pcx', 'png', 'psd', 'psp', 'swc', 'sxd', 'tga',
            'tif', 'tiff', 'wmf', 'wpg', 'xcf', 'xif', 'yuv'),
            'java' => array('class', 'jar', 'jav', 'java', 'jtk'),
            'js' => array('ebs', 'js', 'jse', 'vbe', 'vbs', 'wsc', 'wsf',
            'wsh'),
            'key' => array('aex', 'asc', 'gpg', 'key', 'pgp', 'ppk'),
            'mov' => array('amc', 'dv', 'm4v', 'mac', 'mov', 'mp4v', 'mpg4',
            'pct', 'pic', 'pict', 'pnt', 'pntg', 'qpx', 'qt', 'qti',
            'qtif', 'qtl', 'qtp', 'qts', 'qtx'),
            'movie' => array('asf', 'asx', 'avi', 'div', 'divx', 'dvi', 'm1v',
            'm2v', 'mkv', 'movie', 'mp2v', 'mpa', 'mpe', 'mpeg', 'mpg',
            'mps', 'mpv', 'mpv2', 'ogm', 'ram', 'rmvb', 'rnx', 'rp', 'rv',
            'vivo', 'vob', 'wmv', 'xvid'),
            'pdf' => array('edn', 'fdf', 'pdf', 'pdp', 'pdx'),
            'php' => array('inc', 'php', 'php3', 'php4', 'php5', 'phps',
            'phtml'),
            'ppt' => array('emf', 'pot', 'ppa', 'pps', 'ppt', 'sda', 'sdd',
            'shw', 'sti', 'sxi'),
            'ps' => array('ai', 'eps', 'ps'),
            'sound' => array('aac', 'ac3', 'aif', 'aifc', 'aiff', 'ape', 'apl',
            'au', 'ay', 'bonk', 'cda', 'cdda', 'cpc', 'fla', 'flac',
            'gbs', 'gym', 'hes', 'iff', 'it', 'itz', 'kar', 'kss', 'la',
            'lpac', 'lqt', 'm4a', 'm4p', 'mdz', 'mid', 'midi', 'mka',
            'mo3', 'mod', 'mp+', 'mp1', 'mp2', 'mp3', 'mp4', 'mpc',
            'mpga', 'mpm', 'mpp', 'nsf', 'oda', 'ofr', 'ogg', 'pac', 'pce',
            'pcm', 'psf', 'psf2', 'ra', 'rm', 'rmi', 'rmjb', 'rmm', 'sb',
            'shn', 'sid', 'snd', 'spc', 'spx', 'svx', 'tfm', 'tfmx',
            'voc', 'vox', 'vqf', 'wav', 'wave', 'wma', 'wv', 'wvx', 'xa',
            'xm', 'xmz'),
            'tar' => array('gtar', 'tar'),
            'text' => array('c', 'cc', 'cp', 'cpp', 'cxx', 'diff', 'h', 'hpp',
            'hxx', 'm3u', 'md5', 'patch', 'pls', 'py', 'sfv', 'sh',
            'txt'),
            'uu' => array('uu', 'uud', 'uue'),
            'web' => array('asa', 'asp', 'aspx', 'cfm', 'cgi', 'css', 'dhtml',
            'dtd', 'grxml', 'htc', 'htm', 'html', 'htt', 'htx', 'jsp', 'lnk',
            'mathml', 'mht', 'mhtml', 'perl', 'pl', 'plg', 'rss', 'shtm',
            'shtml', 'stm', 'swf', 'tpl', 'wbxml', 'xht', 'xhtml', 'xml',
            'xsl', 'xslt', 'xul'),
            'xls' => array('csv', 'dbf', 'prn', 'pxl', 'sdc', 'slk', 'stc', 'sxc',
            'xla', 'xlb', 'xlc', 'xld', 'xlr', 'xls', 'xlt', 'xlw'));
            foreach ($icon_types as $png_name => $exts)
            {
            if (in_array($ext, $exts))
            {
            $icon = $png_name;
            break;
            }
            }
            }
            return "<img alt=\"[$ext]\" height=\"16\" width=\"16\" src=\"$icon_pat h/$icon.png\" /> ";
            }
            ?>
            [/PHP]

            Comment

            • ronverdonk
              Recognized Expert Specialist
              • Jul 2006
              • 4259

              #7
              themadmidget: Nice piece of code you showed us. Any chance you could show me a path to the larger 32x32 icons??

              Ronald :cool:

              Comment

              • TheMadMidget
                New Member
                • Oct 2006
                • 98

                #8
                I don't have any but you can get your own from your computer with this.
                For Windows XP users, may I suggest you look (with the above software) at C:\Windows\Syst em32\shell32.dl l and C:\Windows\Syst em32\shimgvw.dl l
                Most system icons are located in .dll files if you are looking for specific icons such as for PDF files, look at the .exe files that reads them ex. C:\Program Files\Adobe\Acr obat 7.0\Reader\Acro Rd32.exe

                Comment

                • ronverdonk
                  Recognized Expert Specialist
                  • Jul 2006
                  • 4259

                  #9
                  Thanks for the tip!

                  Ronald :cool:

                  Comment

                  • rpapaiof
                    New Member
                    • Oct 2006
                    • 27

                    #10
                    Originally posted by ronverdonk
                    Thanks for the tip!

                    Ronald :cool:
                    i get my icons from dll files by icon extractor programs .
                    also thanks for codes my friends they help me very much

                    Comment

                    Working...