Localhost main folder sort

HavaLite CMS

A new liteweight Content Management System (CMS)

Localhost main folder sort

The more files and folders we have in the localhost main folder the worse it is to find anything easly. That's why i decided to make this php script to sort all items the way i like it.

See how it looks like now:

The script contains the most used formats for images which also included as Bas64. If you need another image for your folder, just save a *.png image in the same folder with same name (e.g. "myFolder" image is "myFolder.png").

Copy the script and save in "index.php".

<?php
// define the folder which has to be scaned
$dir = 'C:\\xampp\\htdocs';

// we define some images in base64 instead of pure text
$folder = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAEIUlEQVRYheWWTWwbRRTH/29m19+uG7nBErGAQigKIRRQkWgrJCAtB9QTiBMfFUicaEEFKRKISxVVwBmJI+LADSlq1UOECBJCVUBVoAQ3aZ2EOEpwndR27I3X9q7XO49DkjaOnaiUOJf+LzM7s/ve77198wHc66JWg5qU9x871v8qCSkLhcJysVgsLC0uulXLMi3LmgSQbxtRd3f3gZGRkVFulMvMZcMwFgcGBr4SRLGd8teQgRcP+uVrJ45OHT+8/2HSw9B9EUhPCJonhMC+HkQeeB4AMDw8/NtHZ858dj2ZvAyg9H8AZAMNQX9qP875qxN6ei6BxdQYMjOjSCd/xvyf36NuzmFPrBc9TxyKv/n2W69rUuydTiYzZrm8dLcATTUw+N6jy4ceMjtqDgMAxNq4Wmt9wQ50P3cSXQffgDccx9+plDF59ervY2Nj45lMJmMYhbJymfdEIoFYLBaNx+PxPeFw5/kLF4aGhoZ+ZOa5LQHCoVDHp+88mYgH5rts24YQgJQETQBCEIS4DeT1SHT19CP++CsIdvZC90chNB9I6GtWCQCDlQvXMVG3ivj83OD8/PTYx98Npy4ys90AcPTIkZdOnT79dX7y28esShW1Wg01x4bQ/BBaCMp1wKoOxQrEDKVcMLsQQkDz+CA1H6Tmgab7IKQOKXWQ1AAQCAwiRsDvx75H+mE7/Ovg2bOnxhOJPwAAH37w/ifMbPEuSVk5Pv/NQIKIIgIA+vqefhmA924L6b+KvFEks9EcM3s0AHrh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KsumoGsDCwPZZMbWX09LdPEVt3QdG7Yix3+byWv0v+FvvKx6TzxpiWKSgASDFTCd1b+c1d0p6BnN58c1Vxy7LQrguzcm4pRCUA1ldeiGrlvqh8C5AjiAsG2hVhmnsjphLkAlyVAB9hUqoLg2nDQAmxZz53aZw5f3VYSBFaK2EpBd4UuSRnUuTtv6rvZgYKAIblw7qUVeqCJP8DNwyCGOdWW16EvqjqoOQilhkmKEmUEIYhxhiGw/1fgGkzAwvx9EtAEZbzO7s04jjmaj4nCAKiKCIMQ7rdLgcHP00fP975EkhssxopthgwNQd65DcIA15eXNDpdDArQhwHQMz5+Uvub73/5Ozs7Dv3PE+ibeXKxUMKJav7oHB1ecVvh78TJyG9XpcoChmPJ3z88JMf9r7f23bp96egYMCgCqauF8t3FbHGzGZTTk5PuHP3DS6vLvnnYsSjTx8d7Ox8/g7wq6926muguOWkfLDDW15ycaJMJlOMEeI44fT4lA8/evD1YDC4DzyjZtR2QfVWo74bFIL5nMlkwu07tzn640+2tj74Yn9/fxN4TsN4ZSHyDoFut8v169fY2/txsv3g4WfPj462gZNlphUAh4eHL4bD4Wg8Hk+XGRfRB4Ec/308HQwGP+/u7j4JguArYNIKu/vvOfAmcLd9+DkHjIG/gBdLMVtn/geN/EVtVVXySwAAACV0RVh0ZGF0ZTpjcmVhdGUAMjAxMC0wMi0xMVQxMTo0NjoxNy0wNjowMCBiugsAAAAldEVYdGRhdGU6bW9kaWZ5ADIwMDYtMDQtMTJUMDA6NDA6MTYtMDU6MDD17OHsAAAAAElFTkSuQmCC';

$files = scandir($dir);
natcasesort($files);
$dirSort = '';
$fileSort = '';

foreach($files as $f){
    if($f == '.' or $f == '..'){ }
    elseif (!preg_match('/\\./', $f)) {
        if(file_exists($f.'/'.$f.'.png')) $dirSort .= '<a href="'.$f.'"><img src="'.$f.'/'.$f.'.png"> '.$f.'</a><br>';
        else $dirSort .= '<a href="'.$f.'"><img src="'.$folder.'"> '.$f.'</a><br>';
    }
    else {
        if (preg_match('/\\.(png|jpeg|jpg|gif)/i', $f)) {
            $fileSort .= '<a href="'.$f.'"><img src="'.$f.'"> '.$f.'</a><br>';
        }
        elseif (preg_match('/\\.(htm|html)/i', $f)) {
            $fileSort .= '<a href="'.$f.'"><img src="'.$html.'"> '.$f.'</a><br>';
        }
        elseif (preg_match('/\\.php/i', $f)) {
            $fileSort .= '<a href="'.$f.'"><img src="'.$php.'"> '.$f.'</a><br>';
        }
        elseif (preg_match('/\\.css/i', $f)) {
            $fileSort .= '<a href="'.$f.'"><img src="'.$css.'"> '.$f.'</a><br>';
        }
        elseif (preg_match('/\\.js/i', $f)) {
            $fileSort .= '<a href="'.$f.'"><img src="'.$js.'"> '.$f.'</a><br>';
        }
        elseif (preg_match('/\\.txt/i', $f)) {
            $fileSort .= '<a href="'.$f.'"><img src="'.$txt.'"> '.$f.'</a><br>';
        }
        else {
            $fileSort .= '<a href="'.$f.'"><img src="'.$unknown.'">'.$f.'</a><br>';
        }
        
    }
}
echo $dirSort.$fileSort;
?>

CSS can be like this or change the way you like

body{ font-family:arial; font-size:16px; }
img{ width:20px; height:20px; }
body div{ columns:100px 7; -webkit-columns: 230px 7; -moz-columns: 100px 7; }
a{ color:#000; text-decoration:none; display:inline-block; width:230px; margin-left:8px; }
a:hover{ color:#6633FF; }
a:active{ color:#FF0000; }

Have fun

comments powered by Disqus

0 Comments

    Leave a Reply

    Contact Info

    Phone: +49 941 26175

    Address: Ayman Teryaki,
    Prüfeninger Str. 48,
    93047 Regensburg, Germany

    Want more info - go to our contact page or visit Google+

    Social

    Stay up to date. Subscribe via RSS, Facebook, Twitter or Email

    Recent Comments