24 pers. connectées au site
Manuel Pear
Example
Example -- How to use System_Folders
Using System_Folders
Exemple 63-1. 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
Exemple 63-2. General usage
- <?php
- require_once 'System/Folders/Cached.php';
- $sf = new System_Folders_Cached();
-
- echo 'Config file: ' . $sf->getDefaultConfigFile() . "\r\n";
-
- $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";
-
-
- $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 {
-
- 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.
Remonter