Site Navigation Code
  Home arrow Site Navigation Code arrow Simple File Lister
Codewalker Forums 
  Tutorials  
Database Articles  
Miscellaneous  
Navigation Usability  
PEAR Articles  
Programming Basics  
Server Administration  
XML Tutorials  
  Reviews  
Database Book Reviews  
Linux Book Reviews  
Miscellaneous Reviews  
PHP Book Reviews  
PHP Software Reviews  
Server Admin Reviews  
SQL Tool Reviews  
  Code Gallery  
Content Management Code  
Contest Code  
Counters Code  
Database Code  
Date Time Code  
Discussion Board Code  
Email Code  
File Manipulation Code  
GUI Code  
Link Farm Code  
Miscellaneous Code  
Search Code  
Site Navigation Code  
User Management Code  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Download TestComplete 
Forums Sitemap 
Weekly Newsletter 
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
SITE NAVIGATION CODE

Simple File Lister
By: Codewalkers
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 4
    2005-07-30

    Table of Contents:

    Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Very simple files/sub-dirs/images lister.
    Images get a small thumbnail, and sub-dirs are supported too.


    By : orioriginal

    <?php
    /*
    Files Lister
    ============
    Very simple files/sub-dirs/media lister.
    images get a small thumbnail, and sub-dirs are supported too.

    no need to put the file in every sub-dir, just the most upper one.
    you can assign a relative home-dir, from which the user cannot list out.
    you can cancel the show sub-dirs option.
    you can show only media files if you want.
    support for up-dir (..) is cancelled for security reasons.
    when a file named icon.gif/jpg/ico exists in a sub-dir - it is used as a thumbnail for the sub-dir.

    Installation:
    Just put the file in your home dir, and name it what you want.
    Options:
    parameter method options default description
    ========= ====== ======= ======= ===========
    dir $_GET $dirdef subdir (without a slash)
    media $_GET 1/0 $mediadef hide non-media files

    $homedir variable the base relative home dir. u must add a slash at the end.
    $mediaopt variable 1/0 1 show the option to switch between hide/show non-media files?
    $mediadef variable 1/0 0 media default status, and permanent status when $mediaopt==0
    $showdirs variable 1/0 1 show sub-dirs? when disabled, the dir parameter is also not available


    author: Original (aka OriA)
    date: 2005-07-30
    copyrights: common, it took me 3 minutes of base code (and 2 hours of improovments...)
    feel free to do whatever you want with it :)

    Thats me, Original
    */

    //error_reporting(0);


    // parameters:
    $homedir=''; // relative home dir
    $mediadef=0; // hide non-medias by default?
    $mediaopt=1; // show the option of switching between media mode?
    $showdirs=1; // show sub-dirs?

    // link to me
    $me=basename($_SERVER['PHP_SELF']);

    // current dir
    if ($showdirs){
    echo "Content of ";
    // get sub-dir from GET
    $cdir=''.$_GET['dir'];
    // security - dont allow get out of home-dir by deleting suspicious dir characters
    $cdir=str_replace('\\' ,'/',$cdir);
    while (strpos($cdir,'/..')!==false) $cdir=str_replace('/..','/',$cdir);
    while (strpos($cdir,'/./')!==false) $cdir=str_replace('/./','/',$cdir);
    while (strpos($cdir,'//' )!==false) $cdir=str_replace('//' ,'/',$cdir);
    while (strpos('\\/.',substr($cdir,0,1))!==false) $cdir=substr($cdir,1);
    echo "$cdir/ ";
    }else{
    echo "Content:";
    $cdir=$dir='';
    }
    $dir=$homedir.$cdir;
    if ($dir!='') $dir.='/';

    // show only media files? (media = php mediatypes = medias and swf)
    if ($mediaopt){
    $media=''.$_GET['media'];
    if ($media==='') $media=$mediadef;
    if ($media){
    echo " &nbsp;<a href=\"$me?dir=$cdir&media=0\">(show all files)</a>";
    }else{
    echo " &nbsp;<a href=\"$me?dir=$cdir&media=1\">(hide non-media)</a>";
    }
    }else{
    $media=$mediadef;
    }

    echo "<br>";

    // fix for different code pages
    function fixurl($str){
    //return str_replace('%'.dechex(ord('/')),'/',htmlentities(rawurlencode($str)));
    $ret='';
    for($i=0;$i<strlen($str);$i++){
    if ($str{$i}=='/'){
    $ret.='/';
    }else{
    //$ret.='%'.dechex(ord($str{$i}));
    $ret.=htmlentities(rawurlencode($str{$i}));
    }
    }
    return $ret;
    }

    // show files
    if (!$files=glob($dir."*.*")){
    echo "<i>no files</i><br>";
    }else{
    foreach ($files as $file){
    if (!is_dir($file) && $file!=basename($_SERVER['PHP_SELF'])){

    // thumbnail:

    // once there was a cool exif thumbnail system here - but the simple extensions method prooved to be better...

    // get file extension
    $ext=pathinfo($file);
    $ext=strtolower($ext['extension']);
    $images=array('jpg','jpeg','jp2','jpx','gif','png','ico','bmp','wbmp','tiff','iff','tif','pcx');
    $movies=array('avi','mov','swf','swc');
    $type='';
    if (in_array($ext,$images)) $type='image';
    if (in_array($ext,$movies)) $type='movie';
    $text=$file;
    if ($type=='movie'){
    $text.=" <embed align=middle width=36 height=36 border=0 autostart=false src=\"".fixurl($dir).fixurl(basename($file))."\"></embed>";
    //$text.=" <img align=middle height=36 border=0 src=\"http://www.w3.org/Icons/movie.gif\" />";
    }elseif ($type=='image'){
    $text.=" <img align=middle width=36 height=36 border=0 src=\"".fixurl($dir).fixurl(basename($file))."\" />";
    }
    if ($type || !$media){
    echo "<a href=\"".fixurl($dir).fixurl(basename($file))."\">$text</a><br>";
    }
    }
    }
    }


    // show sub-dirs
    if ($showdirs){
    if ($mediaopt){
    $img="&media=$media";
    }else{
    $img='';
    }

    $d=0;
    $dh = opendir($dir.'.');
    while (false !== ($file = readdir($dh))) {
    if ($file!='..' && $file!='.' && is_dir($dir.$file)) {
    if ($d++==0) echo "<br>Sub-dirs:<br>";
    $text=$file;
    // add an icon to a sub-folder
    if (file_exists($file.'/icon.gif')) $text.=" <img border=1 height=36 width=36 src=\"".fixurl($dir).fixurl($file)."/icon.gif\" />";
    if (file_exists($file.'/icon.jpg')) $text.=" <img border=1 height=36 width=36 src=\"".fixurl($dir).fixurl($file)."/icon.jpg\" />";
    if (file_exists($file.'/icon.jpeg'))$text.=" <img border=1 height=36 width=36 src=\"".fixurl($dir).fixurl($file)."/icon.jpeg\" />";
    if (file_exists($file.'/icon.ico')) $text.=" <img border=1 height=36 width=36 src=\"".fixurl($dir).fixurl($file)."/icon.ico\" />";
    echo "<b><a href=\"$me?dir=".$cdir.($cdir=='' ? '':'/').fixurl(basename($file))."$img\">$text</a><br></b>";
    }
    }
    closedir($dh);

    // show home link
    if ($cdir!='') echo "<br><a href=\"$me?dir=$img\">Back to home dir</a><br>";
    }

    ?>

    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

    More Site Navigation Code Articles
    More By Codewalkers

     

    IBM® developerWorks developerWorks - FREE Tools!


    NEW! Best practices for software analysis: An introduction to the IBM Rational Software Analyzer application

    This whitepaper presents the benefits of successfully introducing static analysis into your organization using IBM Rational Software Analyzer. Additionally, it identifies some common pitfalls that can hinder the effective use of static analysis tooling as well as presents 10 simple strategies designed to help you quickly realize the value of static analysis using Rational Software Analyzer.
    FREE! Go There Now!


    NEW! Cook up Web sites fast with CakePHP, Part 4: Use CakePHP&apos;s Session and Request Handler components

    CakePHP is a stable production-ready, rapid-development aid for building Web sites in PHP. This "Cook up Web sites fast with CakePHP" series shows you how to build an online product catalog using CakePHP.
    FREE! Go There Now!


    NEW! Download IBM Rational Developer for System z

    Download a free trial version of IBM Rational Developer for System z, software that can help you deliver core development capabilities; the power of Java Platform, Enterprise Edition (Java EE); and rapid application development support to diverse enterprise application development teams. With comprehensive development tools to help create, deploy and maintain traditional enterprise and composite applications, Rational Developer for System z enables developers with different technical backgrounds to easily participate in important technology projects.
    FREE! Go There Now!


    NEW! IBM Enterprise Modernization Sandbox for System z: Architecture

    Analysts, architects, and developers who have existing COBOL or PL/I skills and want to extend those skills to deploy new workloads on the mainframe can use the IBM Enterprise Modernization Sandbox for System z to find hands-on walkthroughs of common real world scenarios. The scenarios provide examples of how to rapidly design, create, assemble, test, and deploy high-quality Web, Web services, portal, and SOA applications for IBM CICS, IBM IMS, and IBM WebSphere Application Server.
    FREE! Go There Now!


    NEW! Krugle, developerWorks, and code search

    Ken Krugler, co-founder of code search company Krugle, and Laura Merling, vice president of Marketing and Business Development for Krugle, join to talk about the ins and outs of code search and what it means as a new feature for developerWorks users.
    FREE! Go There Now!


    NEW! Project and Portfolio Management Executive Resource Kit

    Portfolio Management is about effectively managing portfolio value by aligning portfolio investments with business goals. This complimentary e-kit provides a collection of materials that can help you understand how IBM Rational enables and automates best practices for improved governance and clear visibility into portfolio and project performance across the entire IT project lifecycle.
    FREE! Go There Now!


    NEW! The role of integrated requirements management in software delivery

    This paper is about the critical role that a discipline called integrated require­ments management can play in helping to ensure that your business goals and IT investments are continuously aligned—whether you are sourcing, integrat­ing, building or maintaining software. It also looks at ways that automated IBM Rational® products can work together to help you use requirements in the very best way.
    FREE! Go There Now!


    NEW! Webcast: Application security testing and Web compliance

    Join the IBM Watchfire team for an informative discussion on techniques and best practices to proactively manage Web application security and how to effectively build application security testing into the software development lifecycle (SDLC). In this Software Delivery Platform webcast you will learn: How to better understand potential web application security vulnerabilities, best practices and how to effectively integrate application security testing into the software development lifecycle, the importance of detecting and removing software vulnerabilities during application development.
    FREE! Go There Now!


    NEW! Webcast: Eclipse: Empowering the universal platform

    The Eclipse community is constantly working to extend Eclipse's functionality. In this webcast, learn about some of the most important and feature-rich projects under development. From multi-language support to plug-in development, tune in to see what Eclipse is capable of now.
    FREE! Go There Now!


    NEW! Webcast: Quickly provide customized, integrated user interfaces with Lotus Notes 8

    IBM Lotus Notes 8 provides a wide range of developers the ability to provide customized, integrated user interfaces via composite applications and via custom sidebar and toolbar plug-ins. This webcast provides you with tips and techniques to use with out-of-the-box capabilities of Lotus Notes 8, and survey how you can share useful components within your own company and within a larger community.
    FREE! Go There Now!



    All FREE IBM® developerWorks Tools!

    SITE NAVIGATION CODE ARTICLES

    - Simple Menu System
    - Simply image viewer script
    - Simple File Lister
    - Dynamic Error Pages
    - BSoftEditor
    - Yahoo Status
    - Page numbers
    - PHP Search Navigator 1.0
    - Simple Page Navigation
    - An easy page browser ( prev 6 7 8 9 10 next )
    - AutoIndex PHP Script (Directory Indexer)
    - Bs_HtmlNavigation (Navigation and Sitemap cl...
    - Another Paging with Stage
    - Website Navigation via PHP
    - MySQL Paging Class





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek