PHP code example of yzh52521 / webman-filesystem

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

    

yzh52521 / webman-filesystem example snippets


    use yzh52521\Filesystem\Filesystem;
    public function upload(Request $request)
    {
        $file = $request->file('file');
        $stream = fopen($file->getRealPath(), 'r+');
        $path='uploads/'.$file->getUploadName();
        Filesystem::writeStream(
            $path,
            $stream
        );
        fclose($stream);
        return Filesystem::getStorageConfig('local','url').$path;
        
        // Write Files
        $filesystem->write('path/to/file.txt', 'contents');
        // Add local file
        $stream = fopen('local/path/to/file.txt', 'r+');
        $result = $filesystem->writeStream('path/to/file.txt', $stream);
        if (is_resource($stream)) {
            fclose($stream);
        }
        // Update Files
        $filesystem->update('path/to/file.txt', 'new contents');
        // Check if a file exists
        $exists = $filesystem->has('path/to/file.txt');
        // Read Files
        $contents = $filesystem->read('path/to/file.txt');
        // Delete Files
        $filesystem->delete('path/to/file.txt');
        // Rename Files
        $filesystem->rename('filename.txt', 'newname.txt');
        // Copy Files
        $filesystem->copy('filename.txt', 'duplicate.txt');
        // list the contents
        $filesystem->listContents('path', false);
    }