File: example.php

Recommend this page to a friend!
  Classes of Alessandro Quintiliani  >  PHP Recreate Tree  >  example.php  >  Download  
File: example.php
Role: Example script
Content type: text/plain
Description: example of usage on Class RecreateTree
Class: PHP Recreate Tree
Recreate directory trees and copy their files
Author: By
Last change: removed method printTree and added extra information to the comments
Date: 4 years ago
Size: 3,380 bytes
 

Contents

Class file image Download
<?php
/*
 * ***************************************************************************************************
 *
 * File name: example.php
 *
 * Copyright © 2015 Alessandro Quintiliani
 *
 * This file is part of RecreateTree.
 *
 * RecreateTree is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * RecreateTree is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with RecreateTree. If not, see <http://www.gnu.org/licenses/>.
 *
 * ***************************************************************************************************
 */


// create a web directory i.e. tree having the right permission and place Class.CustomExceptions.php, Class.RecreateTree.php and this file
include("Class.CustomExceptions.php");
include(
"Class.RecreateTree.php");


// instantiate the class
$rt = new RecreateTree();

// set absolute or relative path to the source and the destination folder. If the input argument of setPathSrc and/or setPathDest
// is a relative path and you test this script first on Linux operating system and then on Windows operating system (or vice versa)
// without modifying the path, you do not need to change the directory separator ("\" on Windows, "/" on Linux)
// If the input argument is omitted, the full path to the directory containing this file is taken as a default
$rt->setPathSrc('absolute/or/relative/path/to/the/source/directory/with/or/without/trailing/slash');


// destination path. The subtree found under the source path is entirely copied under the destination path
// If the input argument is omitted, the full path to the directory containing this file is taken as a default
$rt->setPathDest('absolute/or/relative/path/to/the/destination/directory/with/or/without/trailing/slash');

// NOTICE: you can also omit the setPathSrc or setPathDest input argument, not both: if you do it, an exception is raised


// set the permission to all destination folders and files
$rt->setPermissionDir(0777); // you can also change the octal code or omit it (the permission mask of the most internal subdirectory common with the source path
                              // is the value assigned with no input argument)
$rt->setPermissionFile(0755); // you can also call the octal code or omit it (0644 is the default value assigned with no input argument)

// the following method creates the tree having absolute or relative path as set in the setPathDest() method and its content is a copy
// of the content inside the absolute or relative path set in the setPathSrc() method.
// All of the folders copied to the destination path will have the permission set in the setPrimissionDir(s) method;
// all of the files created/copied to the destination path will have the permission set in the setPrimissionFile(s) method;
// A number of messages and warnings useful for statistics are also printed on the browser
$rt->makeTree();


?>


For more information send a message to info at phpclasses dot org.