PHP code example of spoova / filemanager

1. Go to this page and download the library: Download spoova/filemanager 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/ */

    

spoova / filemanager example snippets

 

use Spoova\FileManager\FileManager; 

$Filemanager = new FileManager;

   $Filemanager->addDir('some/new/dir'); //full path of new directory
   
 
   $Filemanager->setUrl(__DIR__); //example of setting a url 
   

   $Filemanager->openFile($strict, $path); //full path of new directory
   
 
   $Filemanager->openFile(true, 'some/path/of/file.txt'); 
   

   $Filemanager->setUrl('some/path/of/file.txt');

   $Filemanager->openFile(true);
   

   $Filemanager->openFiles($paths, $files);
   
 
   $Filemanager->openFiles(['file.txt', 'file2.txt'], $get_created_files); 
   

   $Filemanager->setUrl(__DIR__); //specify directory
   

   $folders = $Filemanager->getFolders(); //full path of folders
   

   $folders = $Filemanager->getFolders(false); // names of folders
   

   $files = $Filemanager->getFiles();
   

   $files = $Filemanager->getFiles(false); // names of files
   

   $files = $Filemanager->getFiles(false, false); // names of files without extension name
   

   $contents = $Filemanager->getContents(); //returns both files and folders
   

   $folders = $Filemanager->zipUrl($output_name, $excludes);
   
 
   $Filemanager->setUrl(__DIR__);    
   $Filemanager->zipUrl(); 

   if($Filemanager->zipped()) {

        echo "Zip file created."

   } else {

        echo "Zip file not created!";

   }
   
 
   $Filemanager->setUrl(__DIR__);    
   $Filemanager->zipUrl(); 

   if($Filemanager->zipped()) {

        echo $Filemanager->lastDir(); //directory of zipped file

   } else {

        echo "Zip file not created!";

   }
   

   $Filemanager->copyTo($newdir, $newname, $strict);
   

   $Filemanger->setUrl(__DIR__);

   $Filemanager->zipUrl();

   if($Filemanager->zipped()) {

        $Filemanager->copyTo('some/new/directory', 'zip_one'); //copy zip file to new directory

   }
   

   $Filemanager->moveContentsTo($newdir, $ignore, $moved);
   

   $Filemanger->setUrl(__DIR__);

   $Filemanager->zipUrl();

   if($Filemanager->zipped()) {

        $Filemanager->moveContentsTo('some/new/directory');

   }
   

   $Filemanager->moveTo($newdir, $name, $strict);
   

   $Filemanger->setUrl(__DIR__);

   $Filemanager->zipUrl();

   if($Filemanager->zipped()) {

        $new_name = 'mydir.zip';
        
        $Filemanager->moveTo('some/new/directory', $new_name); //move zipped directory file to new path with new name. 

   }

   

   $Filemanager->move($param1, $param2);
   

   $Filemanger->setUrl(__DIR__.'/'.'folder_or_file_name'); //set a directory or file path
   
   $Filemanger->move(__DIR__.'/destination_directory'); //move to new destination directory

   

   $Filemanger->setUrl(__DIR__); //set a base directory
   
   $Filemanger->move('folder_or_file', __DIR__.'/new_directory'); //move to new existing destination directory

   

   $Filemanager->deleteFile($dir);
   

   $Filemanger->setUrl(__DIR__);

   $Filemanager->deleteFile(); //delete directory
   

   $Filemanager->removeFile($dir, $check);
   

   $Filemanger->setUrl(__DIR__);

   $Filemanager->deleteFile(); //delete directory
   

   $Filemanager->decompress($del, $strict);
   

   $Filemanger->setUrl(__DIR__);

   $Filemanager->zipUrl();

   if($Filemanager->zipped()) {

        $Filemanager->moveTo('some/new/directory'); //move zipped file to new path

   }

   $Filemanager->moveTo('some/old/path', 'some/new/path'); // move from some old to new path
   

   $Filemanager->readFile($key, $separator);
   
 
   $Filemanager->setUrl('user.txt');

   $contents = $Filemanager->readFile(['name'], ":"); // ['name' => 'Foo name']
   

   $Filemanager->setUrl('user.txt');

   $contents = $Filemanager->readFile(['name', 'class']); // ['name' => 'Foo name', 'class'=> 'Foo class']   
   

   $Filemanager->setUrl('user.txt');

   $contents = $Filemanager->readFile(['user'], ":"); // ['user' => '']   
   

   $Filemanager->textLine($number, $position);
   
 
   $Filemanager->setUrl('user.txt');
    
   $contents = $Filemanager->textLine(2); // add two new lines
   

   $Filemanager->setUrl('user.txt');

   $Filemanager->textLine(2, ['after' => 'name']); // add two lines after line of key 'name:'
   

   $Filemanager->textLine($data, $options);
   
 
   $Filemanager->setUrl('user.txt');
    
   $Filemanager->textWrite(['name' => 'foo']); // add two new lines
   
 
   $Filemanager->setUrl('user.txt');    

   $Filemanager->textWrite(['age' => 'foo'], ['after' => 'name', 'separator' => ':']); // add key after "name"
   

   $Filemanager->textUpdate($data, $upds, $separator);
   
 
   $Filemanager->setUrl('user.txt');
    
   $Filemanager->textUpdate(['name' => 'Bar name', 'age' => '50']); // 
   

   $Filemanager->textReplace($data, $separator);
   
 
   $Filemanager->setUrl('user.txt');
    
   $Filemanager->textUpdate(['name' => 'Bar name']); // 
   

   Filemanager::load($url, $separator); 
   

   Filemanager::loadenv($url, $key, $separator); 
   
$path
$files
$name
$dir
$dir
$path
$key
$data
$data
$data
$key