Oneupuploaderbundle : change default directory

171 views Asked by At

Can you give best practices in order to change the default directory of uploaded files (web/uploads/gallery) ?

It would be great if you can use for example some form data (album slug if you are uploading photos into an album) or just simple thing like the year or the month because currently all uploaded files are going in a same directory which is hard to maintain..

Thanks

1

There are 1 answers

0
devsheeep On

This question was answered a few times in the bug tracker. Basically you create a custom namer and include all your dynamic data to the file path. Sub-directories will be created automatically.

namespace AppBundle\Uploader\Naming;

use Oneup\UploaderBundle\Uploader\File\FileInterface;
use Oneup\UploaderBundle\Uploader\Naming\NamerInterface;

class CatNamer implements NamerInterface
{
    public function name(FileInterface $file)
    {
        $product = //...
        return sprintf('%d/%s, $product->getId(), grumpycat.jpg');
    }
}

This way you can create your own folder structure.