Sirius\Upload\Handler::setOverwrite PHP Method

setOverwrite() public method

Enable/disable upload overwrite
public setOverwrite ( boolean $overwrite ) : Handler
$overwrite boolean
return Handler
    public function setOverwrite($overwrite)
    {
        $this->overwrite = (bool) $overwrite;
        return $this;
    }

Usage Example

Ejemplo n.º 1
0
 public function register(Silex\Application $app)
 {
     // This exposes the main upload object as a service
     $app['upload'] = $app->share(function ($app) {
         $allowedExensions = $app['config']->get('general/accept_file_types');
         $uploadHandler = new UploadHandler($app['upload.container']);
         $uploadHandler->setPrefix($app['upload.prefix']);
         $uploadHandler->setOverwrite($app['upload.overwrite']);
         $uploadHandler->addRule('extension', array('allowed' => $allowedExensions));
         return $uploadHandler;
     });
     // This exposes the file container as a configurabole object please refer to:
     // Sirius\Upload\Container\ContainerInterface
     // Any compatible file handler can be used.
     $app['upload.container'] = $app->share(function ($app) {
         $base = $app['resources']->getPath($app['upload.namespace']);
         if (!is_writable($base)) {
             throw new \RuntimeException("Unable to write to upload destination. Check permissions on {$base}", 1);
         }
         $container = new FlysystemContainer($app['filesystem']->getManager($app['upload.namespace']));
         return $container;
     });
     // This allows multiple upload locations, all prefixed with a namespace. The default is /files
     // Note, if you want to provide an alternative namespace, you must set a path on the $app['resources']
     // service
     $app['upload.namespace'] = 'files';
     // This gets prepended to all file saves, can be reset to "" or add your own closure for more complex ones.
     $app['upload.prefix'] = date('Y-m') . '/';
     $app['upload.overwrite'] = false;
 }
All Usage Examples Of Sirius\Upload\Handler::setOverwrite