PHP code example of anteris-dev / file-explorer

1. Go to this page and download the library: Download anteris-dev/file-explorer library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

anteris-dev / file-explorer example snippets



use Anteris\FileExplorer\FileExplorer;

$fileExplorer = new FileExplorer; // This uses the cwd
$fileExplorer = new FileExplorer('/users/foo'); // This uses /users/foo



$fileExplorer->createDirectory('./myFolder'); // Creates the folder here
$fileExplorer->createDirectory('/users/foo/myFolder'); // Creates the folder in /users/foo



use Anteris\FileExplorer\FileExplorer;

$fileExplorer = new FileExplorer('/users/foo');
$fileExplorer->createAndEnterDirectory('testing');
echo $fileExplorer->getCurrentDirectory(); // Returns '/users/foo/testing/'



$fileExplorer->createFile('test.txt', 'Hello world!'); // Will not overwrite test.txt
$fileExplorer->createFile('test.txt', 'Hello world!', true); // Will overwrite test.txt



$fileExplorer->enterDirectory('mySubFolder'); // Relative directory
$fileExplorer->enterDirectory('/users/foo'); // Absolute path



$fileExplorer->exists('myFolder');



use Anteris\FileExplorer\FileObject\Directory;
use Anteris\FileExplorer\FileObject\File;

$items = $fileExplorer->getDirectoryContents();

foreach ($items as $item) {
    if ($item instanceof Directory) {
        echo 'Directory!' . PHP_EOL;
    }

    if ($item instanceof File) {
        echo 'File!' . PHP_EOL;
    }

    echo $file->name . PHP_EOL;
}



use Anteris\FileExplorer\FileExplorer;

$fileExplorer = new FileExplorer('/users/foo');
$fileExplorer->goUp();

echo $fileExplorer->getCurrentDirectory(); // returns /users/



/**
 * Returns /users/foo/desktop/
 */
$path = $fileExplorer->joinPaths('/users', '/foo', 'Desktop');