PHP
  Home arrow PHP arrow Page 8 - File And Directory Manipulation In PHP...
Dev Shed Forums 
Administration  
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 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
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

File And Directory Manipulation In PHP (part 1)
By: icarus, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 64
    2003-08-07

    Table of Contents:
  • File And Directory Manipulation In PHP (part 1)
  • Handle With Care
  • Different Strokes
  • Weapon Of Choice
  • Weather Balloon
  • A Matter Of Existence
  • Permission Granted
  • In Stat We Trust
  • A Short Break

  • 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

    PCmover - $15 Off with Coupon Code CJPH7Q

    File And Directory Manipulation In PHP (part 1) - In Stat We Trust
    (Page 8 of 9 )

    An alternative way of obtaining file information is via the stat() function, which retrieves detailed status information on the named file. The return value from stat() is an array consisting of the following elements (take a look at the PHP manual page for the stat() function for more information on what each array element represents):


    ARRAY WHAT IT
    KEY MEANS
    ------------------------------
    dev device number
    ino inode number
    mode inode protection mode
    nlink number of links
    uid file owner's user ID
    gid file owner's group ID
    rdev device type
    size file size (in bytes)
    atime file's last access timestamp
    mtime file's last modify timestamp
    ctime file's last change timestamp
    blksize filesystem block size
    blocks file's allocated blocks

    Consider the following example, and its output, which illustrate how stat()
    works:


    <?php
    // if form has not yet been submitted
    // display input box
    if (!$_POST['file'])
    {
    ?>
    <form action="<?=$_SERVER['PHP_SELF']?>" method="post">
    Enter file path <input type="text" name="file">
    </form>
    <?
    }
    // else process form input
    else
    {
    echo "Filename: <b>" . $_POST['file'] . "</b><br>";

    // check if file exists
    if (file_exists($_POST['file']))
    {
    // get file status
    $stats = stat($_POST['file']);

    // iterate over array and print information
    foreach ($stats as $k=>$v)
    {
    if (!is_numeric($k))
    {
    echo "$k: <b>$v</b><br>";
    }
    }

    }
    else
    {

    echo "File does not exist! <br>";

    }
    }
    ?>

    </body>
    </html>

    Here's an example of the output:


    Filename: /home/web/apps/library/index.php
    dev: 2049
    ino: 767302
    mode: 33188
    nlink: 1
    uid: 512
    gid: 100
    rdev: 21884
    size: 1503
    atime: 1059626194
    mtime: 1059118092
    ctime: 1059118095
    blksize: 4096
    blocks: 8

    Note that stat() will return -1 for those attributes which are unsupported by the underlying operating system.

    More PHP Articles
    More By icarus, (c) Melonfire


     

       

    PHP ARTICLES

    - Setting Up a Web-based Image Hosting Service
    - Comparing Files and Databases with PHP Bench...
    - Setting Up a Web-Based Image Gallery
    - Using Timers to Benchmark PHP Applications
    - Benchmarking Applications with PHP
    - Setting Up a Web-Based File Manager: PHPfile...
    - Developing a Modular Class For a PHP File Up...
    - Setting Up a Web-Based File Manager: bfExplo...
    - Defining a Custom Function for File Uploader...
    - Parsing Child Nodes with the DOM XML extensi...
    - Creating an Error Handling Module for a PHP ...
    - Accessing Attributes and Cloning Nodes with ...
    - Retrieving Information on Selected Files wit...
    - Handling HTML Strings and Files with the DOM...
    - Building File Uploaders with PHP 5

     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway