PHP code example of sokil / file-storage-bundle

1. Go to this page and download the library: Download sokil/file-storage-bundle 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/ */

    

sokil / file-storage-bundle example snippets




class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            new Knp\Bundle\GaufretteBundle\KnpGaufretteBundle(),
            new Sokil\FileStorageBundle\FileStorageBundle(),
        );
    }
}


namespace AcmeBundle\DependencyInjection;

class AcmeExtension extends Extension
{
    public function load(array $configs, ContainerBuilder $container)
    {
        if (isset($config['attachments_filesystem'])) {
            $container->setParameter(
                $this->getAlias() . '.attachments_filesystem',
                $config['attachments_filesystem']
            );
        }
    }
}



$attachmentFilesystem = $this
    ->get('knp_gaufrette.filesystem_map')
    ->get($this->getParameter('acme.attachments_filesystem'));




$file = new File();
$file
    ->setName('some.txt')
    ->setSize(4242)
    ->setCreatedAt(new \DateTime())
    ->setMime('text/plain')
    ->setHash('some_hash_of_file_content');
            
$this
    ->get('file_storage')
    ->write(
        $file,
        'acme.attachments_filesystem',
        'some content of file'
    );
    
$fileId = $file->getId(); // now you have id of file