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!


    IBM – Taking Web 2.0 to Work

    You'll get answers to many questions and more from David Barnes, Lead Evangelist for IBM Emerging Internet Technologies. David will discuss aspects of Web 2.0 that bring value to corporations, academia, and government. He'll also discuss IBM's vision around Web 2.0, including the importance of remixability and consumability. The discussion will culminate with examples of various IBM Software Group solutions you can use to get ahead of the Web 2.0 adoption curve.
    FREE! Go There Now!


    NEW! Don't wait! Try the Rational Application Developer (RAD) v7.5 open beta code today

    Download the Rational Application Developer (RAD) v7.5 open beta code and start developing applications for the JEE5 standard which features EJB3.0, JPA, JSF 1.2, JSP 2.1 and Servlet 2.5 standards. When you use this beta you will see how you can increase developer productivity for already existing applications with improved support for refactoring, as well as adding new features to existing applications. In addition, the beta provides tooling for JD Edwards, Oracle, SAP, Siebel and PeopleSoft to improve the developer productivity with these enterprise systems.
    FREE! Go There Now!


    NEW! Download DB2 Express-C 9.5

    Visit IBM developerWorks to download IBM DB2 Express-C 9.5, a no-charge version of DB2 Express 9 database server. DB2 Express-C offers the same core data server base features as other DB2 Express editions and provides a solid base to build and deploy applications developed using C/C++, Java, .NET, PHP, and other programming languages.
    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! Successful Change and Release Management for .NET

    Join this webcast to discover the key requirements for successful change and release management. Learn how to extend your .NET environment to improve productivity and collaboration, and address core problems afflicting team development. In this webcast, we’ll review typical challenges faced by customers and how to resolve them with the IBM Rational Change and Release Management solution, including Rational ClearCase, Rational ClearQuest and Rational Build Forge. Replay is available for 9 months.
    FREE! Go There Now!


    NEW! Trial download: IBM Lotus Forms V3.0

    Get a free trial download of IBM Lotus Forms V3.0 (formerly Workplace Forms), which provides a zero-footprint eForms solution to help you automate and move forms-based business processes off the desktop and onto the Web. With Lotus Forms, you can extend applications beyond the firewall by creating a single electronic form document ready for use in both thick and Web 2.0 thin client format.
    FREE! Go There Now!


    NEW! Try the IBM SOA Sandbox for Connectivity

    Visit IBM developerWorks to try the IBM SOA Sandbox for connectivity. The SOA Sandbox for connectivity provides a trial environment with the tooling and components to help you explore how to effectively connect your infrastructure and integrate all of the people, processes and information in your company. Use the hosted sandbox to explore SOA techniques that streamline connecting existing IT assets together, as well as learn how to connect them to new business logic.
    FREE! Go There Now!


    NEW! Try the IBM SOA Sandbox for Process

    Visit IBM developerWorks to try the IBM SOA Sandbox for process. The SOA Sandbox for process focuses on providing a trial environment with the necessary tooling and components required to gain a better understanding of business processes and how to best improve existing business processes to derive value quickly.
    FREE! Go There Now!


    NEW! Using IBM Rational Developer for System z and IBM Rational ClearCase together to manage application development

    Whether you are creating new applications or modifying existing ones, managing integration of new components with traditional z/OS elements is a critical part of building and deploying modern applications. Listen to this webcast to see how IBM can help you optimize your development process using an IDE like Rational Developer for System z that integrates with management tools, such as ClearCase to manage your application development on mainframes.
    FREE! Go There Now!


    NEW! Webcast: Introducing the new Information Server and Solutions community: LeverageInformation

    User communities play an important role in communication and collaboration around products, solutions and other areas of special interest to members. Successful communities are able to provide the right mix of content and services to deliver a value proposition that resonates with each audience. Join Tom Inman, VP of Marketing for Information and Platform Solutions as he introduces the new LeverageINFORMATION community. During this webcast, learn about the value provided by the community and how customers and partners derive value from the community in addressing their own technical and business challenges.
    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 6 Hosted by Hostway
    Stay green...Green IT