cleverFilesystemPlugin - 0.2.0

This plugin permits to have an abstract access to the filesystem, whatever its type

You are currently browsing
the website for symfony 1

Visit the Symfony2 website

« Back to the Plugins Home


Forgot your password?
Create an account



advanced search
Information Readme Releases Changelog Contribute
Show source



This plugin permits to have an abstract access to the filesystem, whatever its type. The plugin currently supports the traditionnal "disk" filesystem and FTP servers, and provides an easy way to add support for additional file storage systems (FTP, etc.).

This plugin is particularly useful for applications that manage files (a media library, a file upload, etc.), as it provides an easy way to abstract the access to the filesystem. Relocating the files to a new file storage system during the life of the application is made a lot easier, as it only consists in using or writing a new filesystem adapter.


  • filesystem access abstraction
  • supports Symfony 1.2
  • ORM agnostic
  • available adapters : disk, ftp
  • unit tests

How to installed

  • go to your project's root

  • Install the plugin:

     ./symfony plugin:install
  • clear cache:

     ./symfony cc


Attaching a filesystem

Attaching a filesystem is a similar operation to mounting a filesystem on your operating system.

// create a "disk" filesystem, locally cached in the /tmp directory
$fs = new cleverFilesystem('Disk', array('root' => '', 'cache_dir' => '/tmp'));

You may also attach a filesystem only by using a configuration defined in the app.yml file:

            type:           ftp
            root:           test_de_serveur_ftp
            host:           localhost
            username:       michel
            password:       test
            cache_dir:      /tmp
            type:           disk
            root:           /path/to/my/project/media
            cache_dir:      /tmp

This can be achieved with a very simple call:

$fs = cleverFilesystem::getInstance('localdisk');

Create a file or a directory

$fs->write('subdir/toto.txt', 'Hello, here is toto');

You may also directly create a file. If the containing directory does not exist, it will be created automatically:

$fs->write('path/to/a/non/existant/dir/toto.txt', 'Hello, here is toto');

In the case of long file contents, you may want to pass a stream as the second parameter:

$long_file = fopen('/path/to/a/long/file', 'r');
$fs->write('subdir/destination.txt', $long_file);

Copy a file within the filesystem

The plugin offers the possibility to copy a file within the filesystem. For some filesystem types which depend on limited protocols, like FTP, this will mean downloading the file/directory for uploading it in its new location:

$fs->copy('subdir/toto.txt', 'an_other_dir/toto.txt');
$fs->copy('subdir', 'path/to/a/non/existing/new/dir');

Delete a file or a directory


Filesystem verification task

The plugin bundles a task which allows to check the validity of the definition of a filesystem in the app.yml file. For instance:

$ ./symfony filesystem:check frontend localdisk

The task will either explain "The filesystem seems to be valid." or "The filesystem "localdisk" does not seem to be reachable.".

Run tests

The tests check the validity of the provided adapters, for each of the proposed methods. In order to successfully run the tests, please edit the first few lines of the file plugins/cleverFilesystemPlugin/test/unit/cleverFilesystemTest.php, in order to use your own parameters. Then, run the following command from your project's root directory:

$ php plugins/cleverFilesystemPlugin/test/unit/cleverFilesystemTest.php


  • SVN filesystem adapter
  • Database filesystem adapter
  • Amazon S3 filesystem adapter
  • file creation / deletion hooks and events
  • more tests!
  • performance improvements

License and credits

This plugin has been developed by Xavier Lacot / Clever Age and is licensed under the MIT license.


version 0.2 - 2009-08-13

Lots of fixes, which helped improve a lot the overall stability.

version 0.1 - 2009-09-14

Initial public release. Features filesystem access abstraction, and supports Disk and FTP filesystems.