I am uploading files using oneup/flysystem-bundle and vich/uploader-bundle and that works fine.
When trying to delete a file with
$this->filesystem->delete($path)
it throws error saying that file not found, although the path is correct.
This question suggests that this may be due $this->filesystem using a relative path.
That may be the case, but relative to what?
Initially I used $path as being the full absolute path. Then I tried a few variants of relative path, but nothing worked.
I know I could just use unlink, but I want to understand this.
This how the config file looks like:
oneup_flysystem:
adapters:
category_image:
local:
directory: "%kernel.project_dir%/public/images/category"
filesystems:
category_image_filesystem:
adapter: category_image
mount: category_image_filesystem
EDIT: Solution as proposed by Bossman
on config:
category_image:
local:
directory: "%kernel.project_dir%/public/images/category"
permissions:
file:
public: 0o644
private: 0o600
dir:
public: 0o755
private: 0o700
on controller:
$filename = $oldImage->getFilename();
if ($filename && $this->filesystem->has($filename)) {
$this->filesystem->delete($filename);
}
The original Flysystem has visibility directives within the config file for file and directory visibility, by default they are private. Make these public.
As shown in step 3:
# app/config/config.yml
oneup_flysystem:
adapters:
my_adapter:
local:
location: "%kernel.root_dir%/cache"
filesystems:
my_filesystem:
adapter: my_adapter
# optional - defines the default visibility of files: `public` or `private` (default)
visibility: private
# optional - defines the default visibility of directories: `public` or `private` (default)
directory_visibility: private
For more control the file and directory visibility properties can be set like this, like chmod:
# app/config/config.yml
oneup_flysystem:
adapters:
my_adapter:
local:
location: "%kernel.root_dir%/../uploads"
lazy: ~ # boolean (default "false")
writeFlags: ~
linkHandling: ~
permissions:
file:
public: 0o644
private: 0o600
dir:
public: 0o755
private: 0o700
Related
Is there a way to set a parameter in symfony based on a certain condition, f.e. an ENV var?
Expression language came to my mind but it seems its only supported in arguments, properties and calls
config.yml:
parameters:
env(CI): false
ci: '%env(CI)%'
database_host: "#=parameter(ci) ? 'localhost' : 'mysql'"
doctrine:
dbal:
connections:
cms:
host: "%database_host%"
UPDATE
Expression language doesnt work in that case (Up to SF 3.3 currently) so i used Oli's approach which works:
get_params_from_env.php:
$container->setParameter('database_host', 'mysql');
if (getenv('CI')) {
$container->setParameter('database_host', '127.0.0.1');
}
Add this line to config.yml:
imports:
- { resource: get_params_from_env.php }
Then, in the php file, use this:
<?php
$container->setParameter('app.dummy_var', getenv('DUMMY_VAR'));
You can read about including your own PHP files here, under 'advanced techniques': http://symfony.com/doc/current/configuration/configuration_organization.html
I trying to install SonataAdmin on my Symfony Project but at the end of the part-2 of the documention when i'm trying to go on "http://localhost:8000/admin/" I have a error : "You have requested a non-existent service "admin.category" in . (which is being imported from "C:\wamp64\www\Sonata/app/config\routing.yml"). Make sure there is a loader supporting the "sonata_admin" type."
I have no idea why, i give give my all my parameters code maybe it's can help you to understand my problem.
parameters:
#parameter_name: value
services:
# default configuration for services in *this* file
_defaults:
# automatically injects dependencies in your services
autowire: true
# automatically registers your services as commands, event subscribers, etc.
autoconfigure: true
# this means you cannot fetch services directly from the container via $container->get()
# if you need to do this, you can override this setting on individual services
public: false
admin.category:
class: AppBundle\Admin\CategoryAdmin
arguments: [~, AppBundle\Entity\Category, ~]
tags:
- { name: sonata.admin, manager_type: orm, label: Category }
# makes classes in src/AppBundle available to be used as services
# this creates a service per class whose id is the fully-qualified class name
AppBundle\:
resource: '../../src/AppBundle/*'
# you can exclude directories or files
# but if a service is unused, it's removed anyway
exclude: '../../src/AppBundle/{Entity,Repository,Tests}'
# controllers are imported separately to make sure they're public
# and have a tag that allows actions to type-hint services
AppBundle\Controller\:
resource: '../../src/AppBundle/Controller'
public: true
tags: ['controller.service_arguments']
# add more services, or override services that need manual wiring
# AppBundle\Service\ExampleService:
# arguments:
# $someArgument: 'some_value'
`
The indentation is going wrong i add you a picture of this file. Service code
The sonata admin services must be public. In your config, you have default as public: false and that is why you get this error.
So you have 2 options:
Specify public: true for your admin service (in your example file)
Or the better way: create a new services file (eg admin.yml) where you dont use these defaults (the _defaults key with public: false). Public is true by default, so you don't have to specify that by _defaults. In this case you must import your new file in config.yml to work:
Top of app/config.yml
imports:
- { resource: parameters.yml }
- { resource: security.yml }
- { resource: services.yml }
- { resource: admin.yml }
app/admin.yml content:
services:
admin.category:
class: AppBundle\Admin\CategoryAdmin
arguments: [~, AppBundle\Entity\Category, ~]
tags:
- { name: sonata.admin, manager_type: orm, label: Category }
I think you did a mistake by writing your category.admin service in: Sonata/app/config/routing.yml,
instead of Sonata/src/YourAdminBundle/Resources/config/services.yml
Run this command on terminal. Because You might have missed installing
php composer.phar require sonata-project/doctrine-orm-admin-bundle
After This Add this code below to your AppKernel.php
// app/AppKernel.php
public function registerBundles()
{
return array(
// ...
// set up basic sonata requirements
// ...
new Sonata\DoctrineORMAdminBundle\SonataDoctrineORMAdminBundle(),
// ...
);
}
I have this this config:
liip_imagine:
resolvers:
default:
web_path: ~
filter_sets:
cache: ~
subitem_in_category:
path: ~ ///how to change the default path where the images are saved?
filters:
my_custom_filter: { }
relative_resize: { heighten: 210 }
Im trying to change the name of the directory wheren the images are saved, but I get
InvalidConfigurationException: Unrecognized options "path" under
"liip_imagine.filter_sets.subitem_in_category"
I have read this: https://github.com/liip/LiipImagineBundle/blob/master/Resources/doc/configuration.md
The features was removed some time ago for bad design about component dependency. See this pull request for further motivations about this.
For the same features suggest to configuring several resolvers, as described here:
liip_imagine:
resolvers:
foo:
web_path:
cache_prefix: foo
bar:
web_path:
cache_prefix: bar
filter_sets:
foo:
cache: foo
bar:
cache: bar
Else you can use an old branch of the bundle.
Hope this help
So I have my KnpGaufretteBundle configured like this:
knp_gaufrette:
adapters:
local_shared:
local:
directory: "%shared.dir%"
create: false
filesystems:
local_shared:
adapter: local_shared
alias: defaul_fs
Then I need to inject it to my own service, I do this:
acme.user_manager:
class: %acme_user.user_manager.class%
arguments: [#doctrine.orm.entity_manager, #security.context]
calls:
- [setFilesystem, [#default_fs]]
But this breaks with exception The service definition "default_fs" does not exist.
If I use #gaufrette.local_shared_filesystem as a parameter instead of #default_fs then it works like expected. But I would like to use an alias.
Please help.
I'm assuming that you noticed that you have a typo in your config declaration:
alias: defaul_fs
has no "t"
I use VichUploaderBundle for upload my media files and I want to use AvalancheImagineBundle to create thumbs in my templates.
How it should be done?
I have this right now:
<td><img src="{{ vich_uploader_asset(entity, 'image') | apply_filter('my_thumb')}}" alt="{{ entity.nombre }}" /></td>
But the output is:
<img src="/app_dev.php/media/cache/my_thumb/images/uploads/392158_10150441208223772_580903771_8591661_774015725_n.jpg" alt="Froga"/>
this is my config.yml:
# Vich Uploader
vich_uploader:
db_driver: orm
twig: true
gaufrette: false # set to true to enable gaufrette support
storage: vich_uploader.storage.file_system
mappings:
uploads:
uri_prefix: /images/uploads
upload_destination: %kernel.root_dir%/../web/images/uploads
namer: ~ # specify a file namer service id for this entity, null default
directory_namer: ~ # specify a directory namer service id for this entity, null default
delete_on_remove: true # determines whether to delete file upon removal of entity
inject_on_load: true # determines whether to inject a File instance upon load
avalanche_imagine:
source_root: %kernel.root_dir%/../web/images/uploads
web_root: %kernel.root_dir%/../web/images/uploads
cache_prefix: media/cache
driver: gd
filters:
my_thumb:
type: thumbnail
options: { size: [120, 90], mode: outbound, quality: 100, format: png }
Any help or clue?
If the problem you are having is that no image is being displayed, then I had the same issue.
In order to solve it I ensured that within my config.yml, the source_root and web_root options of avalanche_imagine were set to %kernel.root_dir%/../web (or your web root). Here is the relevant snippet from my config.yml:
#Uploads
knp_gaufrette:
adapters:
article_adapter:
local:
directory: %kernel.root_dir%/../web/images/articles
filesystems:
article_image_fs:
adapter: article_adapter
vich_uploader:
db_driver: orm
gaufrette: true
storage: vich_uploader.storage.gaufrette
mappings:
article_image:
uri_prefix: /images/articles
upload_destination: article_image_fs
namer: vich_uploader.namer_uniqid
#images
avalanche_imagine:
filters:
article_list:
type: thumbnail
options: { size: [100, 100], mode: outbound }
source_root: %kernel.root_dir%/../web
web_root: %kernel.root_dir%/../web
cache_prefix: cache
Nothing wrong with that. Imagine bundle in production generates thumbnail the first time its called and stores it in web/media folder. On second call it just reads from web/media.
It has some advantages to modify the thumnail sizes at will. If You are worried about performance you should fire some job to generate thumbnail after the upload is finished,
although i used it like that and never complained.
In my case, I chose to use LiipImagineBundle which is a fork of the AvalancheImagineBundle
.
I were configure this bundle to use gaufrette as data-loader, than it simple to use it as you describe, without caring much about the paths.