Login   Register  
PHP Classes
elePHPant
Icontem

File: directory.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Alone In The Dark  >  ClassDirectory  >  directory.php  >  Download  
File: directory.php
Role: Unit test script
Content type: text/plain
Description: Use for modify - create directory
Class: ClassDirectory
Creating and acessing file system directories
Author: By
Last change:
Date: 11 years ago
Size: 5,204 bytes
 

Contents

Class file image Download
<?php
//************************************************************************
// By Rosario Sensale
// Date: 2003 - 08 - 21
// Ver.: 1.00.00
// Function:
//           * SetName
//           * CreateDir
//           * GetDirName
//           * DeleteDir
//           * OpenConnectDir
//           * WorkDirectory
//           * OpenDir
//           * ViewTreeWitoutLink
//           * ClosePointer
//
//
// example:
// include_once 'Directory.php';
// $object = new ClassDirectory();
// $object->SetName("Admin");
// $object->OpenConnectDir();
// $object->CreateDir("prova");
// echo "Ti trovi nella cartella : ". $object->WorkDirectory() ."<br>";
// echo "Contenuto directory:<br> ";
// $object->ViewTreeWitoutLink();
// echo "<br>";
// $object->ReloadPointer();
//************************************************************************

class ClassDirectory {
    var 
$name_directory;
    var 
$open_handle;
    var 
$read;

    
//Class construct
    
function __construct(){
        
$this->name_directory='';
        
$this->open_handle='';
        
$this->read='';
    }

    
//Class destruct
    
function __destruct(){
    }

    
//Set var
    
function SetName($namedirectory){
        
$this->name_directory=$namedirectory;
    }
    
    
//Get name of path from complete path
    //(/user/pippo/pippo.php->/user/pippo)
    
function GetDirName($path){
        if (!isset(
$this->name_directory)){
            echo 
"You must set name of directory.";
        }else{
            return 
dirname($this->name_directory);
        }
    }

    
//Make a directory
    
function CreateDir($namedirectory){
        if (!isset(
$this->name_directory)){
            echo 
"You must set name of directory.";
        }else{
            if (!isset(
$this->open_handle)){
                echo 
"You must open directory (use OpenConnectDir).";
            }else{
                if (
is_dir($namedirectory)==false){
                    return 
mkdir($namedirectory);
                }
            }
        }
    }

    
//Delete Directory
    
function DeleteDir($namedirectory){
        if (!isset(
$this->name_directory)){
            echo 
"You must set name of directory.";
        }else{
            if (!isset(
$this->open_handle)){
                echo 
"You must open directory (use OpenConnectDir).";
            }else{
                if (!
is_dir($namedirectory)){
                    echo 
"$namedirectory is not a directory.";
                }else{
                    return 
rmdir($namedirectory);
                }
            }
        }
    }

    
//Work directory
    
function WorkDirectory(){
        if (!isset(
$this->name_directory)){
            echo 
"You must set name of directory.";
        }else{
            if (!isset(
$this->open_handle)){
                echo 
"You must open directory (use OpenConnectDir).";
            }else{
                return 
getcwd();
            }
        }
    }

    
//Apre la directory indicata dalla variabile
    //$name_directory
    
function OpenConnectDir(){
        if (!isset(
$this->name_directory)){
            echo 
"You must set name of directory.";
        }else{
            
//check it is directory
            
if (!is_dir($this->name_directory)){
                echo 
"The $this->name_directory is not a directory!!";
            }else{
                
$this->open_handle opendir($directory);
            }
        }
    }

    
//Open directory
    
function OpenDir($namedirectory){
        if (!isset(
$this->name_directory)){
            echo 
"You must set name of directory.";
        }else{
            
//check it is directory
            
if (!is_dir($this->name_directory)){
                echo 
"The $this->name_directory is not a directory!!";
            }else{
                
chdir($namedirectory);
            }
        }
    }
    
    
//Visualizza a video le directory
    
function ViewTreeWitoutLink(){
        if (!isset(
$this->name_directory)){
            echo 
"You must set name of directory.";
        }else{
            if (!isset(
$this->open_handle)){
                echo 
"You must open directory (use OpenConnectDir).";
            }else{
                while(
$this->read readdir($this->open_handle)) {
                    echo 
$this->read "<br>\n";
                }
            }
        }
    }

    
//Reload pointer of dir
    
function ReloadPointer(){
        if (!isset(
$this->name_directory)){
            echo 
"You must set name of directory.";
        }else{
            if (!isset(
$this->open_handle)){
                echo 
"You must open directory (use OpenConnectDir).";
            }else{
                
rewinddir($this->open_handle);
            }
        }
    }

    
//Close Pointer
    
function ClosePointer(){
        if (!isset(
$this->name_directory)){
            echo 
"You must set name of directory.";
        }else{
            if (!isset(
$this->open_handle)){
                echo 
"You must open directory (use OpenConnectDir).";
            }else{
                
closedir($this->open_handle);
            }
        }
    }

}
?>