Пример

Пример – How to use System_Folders

Using System_Folders

General usage

<?php
require_once 'System/Folders.php';

$sf = new System_Folders();

$arData = array(
'Username'         => $sf->getUserName(),
'Home'             => $sf->getHome(),
'Documents'        => $sf->getDocuments(),
'Shared documents' => $sf->getSharedDocuments(),
'Temp'             => $sf->getTemp(),
'Desktop'          => $sf->getDesktop(),
'AppData'          => $sf->getAppData(),
'Programs'         => $sf->getPrograms(),
'Windows'          => $sf->getWindows()
);

echo 
'System: ' $sf->getSys() . "\r\n";
var_dump($arData);
?>

At first, you need to instantitiate a new System_Folders object. The operating system is determined there, which is needed for all the other methods.

Then just use the getXXX() methods to retrieve the folder locations. Remember that they return NULL if the location can't be determined.

Using System_Folders_Cached

General usage

<?php
require_once 'System/Folders/Cached.php';
$sf = new System_Folders_Cached();

//show the path of the config file
echo 'Config file: ' $sf->getDefaultConfigFile() . "\r\n";

//load the stored settings from last time
$err $sf->loadFromFile();

echo 
'Home:      ' $sf->getHome() . "\r\n";
echo 
'Documents: ' $sf->getDocuments() . "\r\n";

echo 
"\r\n";

$doc $sf->getDocuments();
if (
file_exists($doc)) {
    echo 
"Setting new Documents directory\r\n";
    
//Set an own documents directory
    // and save the settings for next time
    
$sf->setDocuments('/strange/path/to/MyDocuments/');
    
$sf->saveToFile();
    echo 
'New Documents directory: ' $sf->getDocuments() . "\r\n";
    echo 
"Run this program again to reset the path to default\r\n";
} else {
    
//unset the path
    
echo "Unsetting the documents directory\r\n";
    
$sf->setDocuments(null);
    
$sf->saveToFile();
    echo 
'New Documents directory: ' $sf->getDocuments() . "\r\n";
}
?>

This example displays the location of the config file (in which the folder settings are stored), shows some folder locations and sets the documents directory to a (probably non-existing) directory and saves the folder locations.

In the next program call, the documents directory is reset to the normal one and saved again.

    Поддержать сайт на родительском проекте КГБ