PHP
  Home arrow PHP arrow Page 2 - File Management with PHP
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
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? 
Google.com  
PHP

File Management with PHP
By: Murali Dharan.M
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 75
    2004-03-29


    Table of Contents:
  • File Management with PHP
  • Building the Database
  • File_Size() and Display_form Functions
  • The Main Program

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log 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


    File Management with PHP - Building the Database
    ( Page 2 of 4 )

    Name the database "upload". The database contains the table 'file_manager', which manages file information. The SQL statement for creating the table:


    CREATE TABLE file_manager (
    file_name varchar
    (50) default NULL

    file_type varchar
    (20NOT NULL default ''
    file_size varchar
    (20NOT 
    NULL 
    default ''
    file_modified varchar
    (20NOT NULL default ''

    file_parent_id mediumint
    (9) default NULL
    file_image_name varchar
    (50
    default 
    NULL
     
    KEY file_name (file_name), 
    KEY file_image_name 
    (file_image_name)

    TYPE=MyISAM

    File Management
    I've written two programs to manage this file version. The first uploads the file (file_upload_manager.php), the second displays the file (file_upload_manager.php). The source code is tested on a Windows system.

    NOTE:  Linux users, please change the folder path accordingly.

    File Upload Manager:
    This program displays a menu to select the file in your system, a check box and an Upload button. Once the user clicks the upload button, the program checks the file for existence, and undergoes a series of tests as described in the plan.

    Now let's look at the code snippets used in the program.


    $dir_path Variable:

    This variable is the destination folder path.


    $dir_path"C:apachehtdocsfilemanager";

    This path is given for Windows-based systems. Please change your destination folder accordingly.


    Get_New_File_Name() Function:

    This function is called from the main program when the program encounters files that exist and show a difference in size, date or time. This function will generate a new file name and return to the main function.


    function Get_New_FIle_Name($file_name)
    {
      
    $sqlQuery
    ="SELECT  file_image_name FROM file_manager WHERE  file_name 
    LIKE '$file_name%' AND  file_parent_id=1"
    ;
     
      
    $fResult=mysql_query($sqlQuery);
      $Last_Version
    =0;
      
    $ver
    =0;
     
      if(
    mysql_num_rows($fResult)){
          
    while($fRow=mysql_fetch_array($fResult)){          

     
    list(
    $junk,$ver)=explode("_VERSION",$fRow['file_image_name']);
             
    list($ver,$extn)=explode(".",$ver);
             
    $Last_Version 
    $Last_Version $ver $Last_Version 
     
    $ver;
           
    }
      
    }else{
          $new_file_name 
    =$file_name."_VERSION".++$Last_Version;
          
    return 
    $new_file_name;
      
    }
     
      if(
    $Last_Version !=0){
          
    $new_file_name
    =$file_name."_VERSION".++$Last_Version;
          
    return $new_file_name;
      
    }
    }

    The sql query in the beginning of the function will fetch file names of previous versions. If the sql query returns record sets, it means the file has previous versions. The while loop is executed to store the generated version number, and the value obtained is stored in $Last_Version. Otherwise, the new file name will be generated as file-name_VERSION1.

    The next if statement checks for $Last_Version != 0, if true, $Last_Version is incremented by 1 and a new file name is assigned.

    The return statement will return a new file name generated to the called statement.



     
     
    >>> More PHP Articles          >>> More By Murali Dharan.M
     

       

    PHP ARTICLES

    - Implementing Factory Methods in PHP 5
    - Merging a File Split for FTP Upload using PHP
    - Getting Data from Yahoo Site Explorer Inboun...
    - Method Chaining: Adding More Selecting Metho...
    - How to Split a File During an FTP Upload Usi...
    - Expanding a Custom CodeIgniter Library with ...
    - Using the Yahoo Site Explorer Inbound Links ...
    - Building a CodeIgniter Custom Library with M...
    - Building an E-mini Trading System Using PHP ...
    - Completing the MySQL Class with Method Chain...
    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL





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