PHP code example of anfallnorr / file-manager-system

1. Go to this page and download the library: Download anfallnorr/file-manager-system 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/ */

    

anfallnorr / file-manager-system example snippets


# config/bundles.php
return [
    ...
    Anfallnorr\FileManagerSystem\FileManagerSystem::class => ['all' => true],
];

public function __construct(
    private FileManagerService $fmService
) {
    $fmService
        ->setDefaultDirectory('/var/uploads')
        ->setRelativeDirectory('/var/uploads');
}

$fmService = $this->fmService;

// Get the default upload directory path
$defaultDirectory = $fmService->getDefaultDirectory(); // /path/to/folder/public/uploads

// Change the default upload directory
$directory = $fmService->setDefaultDirectory($directory = '/var/www/uploads')->getDefaultDirectory(); // /path/to/folder/var/www/uploads

// Retrieve available MIME types
$mimeTypes = $fmService->getMimeTypes(); // array

// Get the MIME type of a specific extension
$mimeType = $fmService->getMimeType($key = 'pdf'); // application/pdf

// Create a URL-friendly slug from a string
$string = $fmService->createSlug($string = 'Hello World !'); // hello-world

// Create a directory named "hello-world" inside the default directory
$fmService->createDir($directory = 'Hello World !', $return = false);
// if $return is `true`, then an array will be returned:
[
    'absolute' => $this->getDefaultDirectory() . '/hello-world', // Absolute path
    'relative' => $relative, // Relative path of the folder
    'ltrimed_relative' => ltrim($relative, '/'), // Relative path of the folder minus a slash at the beginning of the string
    'foldername' => $dir // The name of the folder created
]

// Create a file named "hello-world.html" inside the default directory with content
$fmService->createFile($filename = 'Hello World.html', $content = 'Hello World! I\'m Js info'); // $content is optional