PHP
  Home arrow PHP arrow Page 7 - 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

    TestComplete™ automates software testing for a fraction of what the big guys charge. Easy functional and load testing for all Windows, .NET, Java and Web apps. Download a free trial now.

    File And Directory Manipulation In PHP (part 1) - Permission Granted
    (Page 7 of 9 )

    In addition to obtaining basic information on a file, PHP also comes with a set of functions designed to provide information on file sizes, permissions and modification times. Here's a list:

    filesize() - gets size of file

    filemtime() - gets last modification time of file

    filemtime() - gets last access time of file

    fileowner() - gets file owner

    filegroup() - gets file group

    fileperms() - gets file permissions

    filetype() - gets file type

    Consider the following example, which asks for a file name and displays the above information for that file:


    <html>
    <head>
    </head>

    <body>

    <?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']))
    {
    // print file size
    echo "File size: <b>" . filesize($_POST['file']) . " bytes</b><br>";

    // print file owner
    echo "File owner: <b>" . fileowner($_POST['file']) . "</b><br>";

    // print file group
    echo "File group: <b>" . filegroup($_POST['file']) . "</b><br>";

    // print file permissions
    echo "File permissions: <b>" . fileperms($_POST['file']) . "</b><br>";

    // print file type
    echo "File type: <b>" . filetype($_POST['file']) . "</b><br>";

    // print file last access time
    echo "File last accessed on: <b>" . date("Y-m-d",
    fileatime($_POST['file'])) . "</b><br>";

    // print file last modification time
    echo "File last modified on: <b>" . date("Y-m-d",
    filemtime($_POST['file'])) . "</b><br>";

    }
    else
    {
    echo "File does not exist! <br>";
    }

    }
    ?>

    </body>
    </html>

    Here's the output:


    Filename: /apps/inventory_control/reports.php
    File size: 1503 bytes
    File owner: 512
    File group: 100
    File permissions: 33188
    File type: file
    File last accessed on: 2003-07-31
    File last modified on: 2003-07-25

    Note that the various file functions discussed in this section only return valid values if the underlying operating system supports them. On Windows, for example, it's quite likely that the fileowner(), filegroup() and
    fileperms() functions will return null values.

    More PHP Articles
    More By icarus, (c) Melonfire


     

       

    PHP ARTICLES

    - 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
    - Working with Multiple Document Nodes with th...

     
    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 5 hosted by Hostway