PHP
  Home arrow PHP arrow Page 4 - Uploading Files and Navigating Directo...
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Mobile Linux 
App Generation ROI 
VPS Hosting 
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? 
PHP

Uploading Files and Navigating Directories in PHP
By: Jacques Noah
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 8
    2006-08-30

    Table of Contents:
  • Uploading Files and Navigating Directories in PHP
  • Uploading files
  • Multiple file uploads
  • Navigating Directories

  • 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


    Uploading Files and Navigating Directories in PHP - Navigating Directories


    (Page 4 of 4 )

    Before we start with the next section, please make sure that you are familiar with file permissions. Pretty much everything in the File Permissions section applies to the directories. To navigate through a directory, you begin by opening the directory with opdir() function:

    $dir = opendir('directoryname');

    As with reading and writing files, you create a pointer that can be referenced by the opened directory. To read the list of files within a directory you use the readdir() function, in a while loop:

    while($thedir=readdir($dir)){
    //write the file details here
    }

    and then you finally close the open directory with the closedir() function:

    closedir($dir);

    Other functions that we are going to use include:

     filesize() function - gives you the size of  the file in bytes.

    filetime() - retrieves the modification time of a file.

    Both of these functions are going to help us to create a directory listing.

    Let's build a script that will show us the insides of a directory listing:

    Script: browsedir.php

    This script will list file names, file size and modification dates:

    <html>
    <head>
      <title>Browse Directories</title>
    </head>
    <body>
    <p>Browsing</p>
    <?php
      $current_dir = '.';
      $dir = opendir($current_dir);
    echo "Current directory is <b>$current_dir</b><br />";
    echo' <table width="100%" border="0" cellspacing="1">
      <tr>
        <td width="34%"><b>File Name</b> </td>
        <td width="26%"> <b>File Size </b></td>
        <td width="40%"><b>Last Modified</b> </td>
      </tr>';
      while ($file = readdir($dir))
      {
      $fs=filesize($file);
      $moddate=date('F j, Y',filemtime($file));
    echo ' <tr>
        <td>'.$file.'</td>
        <td>'.$fs. ' bytes</td>
        <td>'.$moddate.'</td>';              

      }
       closedir($dir);
    ?>
      </tr>
      </table>
    </body>
    </html>

    Fig5. Shows a list of all the files in the current directory, represented here by a dot(.) 

    Conclusion

    This concludes our file and directory handling exploration. 


    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.

       · Nice article. One thing I would like to add is that it's very hard to see the upload...
       · Will look into it. I think PHP comes with certain add ons that have that kind of...
     

       

    PHP ARTICLES

    - Working With Different Namespaces in PHP 5
    - User Management Explained: Overview
    - Using Namespaces in PHP 5
    - Database Security: Guarding Against SQL Inje...
    - Building a Modular Exception Class in PHP 5
    - Database and Password Security for Web Appli...
    - Handling MySQL Data Set Failures in PHP 5
    - Building Site Registration for Web Applicati...
    - Intercepting Customized Exceptions in PHP 5
    - Securing Your Web Application Against Attacks
    - Sub Classing Exceptions in PHP 5
    - Authentication for Web Application Security
    - Building a Content Management System with Co...
    - Filters and Login Systems for Web Applicatio...
    - Working with the Email Class in Code Igniter





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
    Stay green...Green IT