[英]SonataMediaBundle: Files/Images not found
I'm using SonataMediaBundle with SonataAdminBundle and Symfony 2.3. 我正在使用SonataMediaBundle和SonataAdminBundle以及Symfony 2.3。
When I try to upload an image via the Sonata Admin interface: 当我尝试通过Sonata Admin界面上传图像时:
app_dev.php/admin/sonata/media/media/create
) app_dev.php/admin/sonata/media/media/create
) app_dev.php/admin/sonata/media/media/create?provider=sonata.media.provider.image&context=default
) app_dev.php/admin/sonata/media/media/create?provider=sonata.media.provider.image&context=default
) image.jpg
file and click on "create" image.jpg
文件并单击“创建” Item "image.jpg" has been successfully created.
Item "image.jpg" has been successfully created.
And indeed: 事实上:
web\\uploads\\media\\default\\0001\\01
I have my image file and the 3 thumbs web\\uploads\\media\\default\\0001\\01
我有我的图像文件和3个拇指 media__media
DB table I have the corresponding line media__media
数据库表中,我有相应的行 web/uploads/media/default/0001/01/
with Firefox I can see my image web/uploads/media/default/0001/01/
,我可以看到我的图像 But : 但是 :
app_dev.php/admin/sonata/media/media/3/edit?provider=sonata.media.provider.image&context=default
) app_dev.php/admin/sonata/media/media/3/edit?provider=sonata.media.provider.image&context=default
) For the files, it's even worse: 对于文件,情况更糟:
app_dev.php/admin/sonata/media/media/create
) app_dev.php/admin/sonata/media/media/create
) app_dev.php/admin/sonata/media/media/create?provider=sonata.media.provider.file&context=default
) app_dev.php/admin/sonata/media/media/create?provider=sonata.media.provider.file&context=default
) document.zip
file and click on "create" document.zip
文件并单击“创建” This generates the error 500: The file "" does not exist
. 这会生成错误500:
The file "" does not exist
。 And no new line is created in the DB. 并且DB中没有创建新行。
Piece of solution 一块解决方案
For the image problem, I noticed that the path where sonata admin was looking was not the good one: I it looking in: http://myserver/uploads/media/default/0001/01/c35f187f1b405f4bfba8b962d83e5bbdccff54f9.jpeg
对于图像问题,我注意到sonata管理员看的路径不是很好的:我查看它:
http://myserver/uploads/media/default/0001/01/c35f187f1b405f4bfba8b962d83e5bbdccff54f9.jpeg
Instead of http://myserver/myproject/web/uploads/media/default/0001/01/c35f187f1b405f4bfba8b962d83e5bbdccff54f9.jpeg
而不是
http://myserver/myproject/web/uploads/media/default/0001/01/c35f187f1b405f4bfba8b962d83e5bbdccff54f9.jpeg
Apparently, this is due to this part of the config.yml (as defined in SonataMedia documentation): 显然,这是由于config.yml的这一部分(如SonataMedia文档中所定义):
sonata_media
cdn:
server:
path: /uploads/media
That I replaced by: 我改为:
sonata_media
cdn:
server:
path: /myproject/web/uploads/media
And it works. 它有效。 But I don't think it's a good idea to hardcode this there.
但我不认为在那里硬编码是个好主意。 And I guess that there is a good reason why it it written this way in the Sonata Doc, no?
我想有一个很好的理由为什么它在Sonata Doc中以这种方式编写,不是吗?
Is my modification correct? 我的修改是否正确? If not, how should I do?
如果没有,我该怎么办?
In any case, it doesn't solve my file uploading problem! 无论如何,它无法解决我的文件上传问题! Any idea on this point?
关于这一点有什么想法吗?
The file "" does not exist
文件“”不存在
As explained here , this is caused by insufficient limit for allowed upload file size in php.ini (increase upload_max_filesize
and post_max_size
). 正如解释在这里 ,这是通过限制在php.ini允许上传的文件大小(增幅不足而引起
upload_max_filesize
和post_max_size
)。
Then you will probably stumble on another error saying that the zip file type is not allowed, so add this into your config.yml: 然后你可能会偶然发现另一个错误,说不允许使用zip文件类型,所以将它添加到你的config.yml中:
sonata_media:
providers:
file:
allowed_extensions: ['zip']
sonata_media
cdn:
server:
path: /myproject/web/uploads/media
This is the working option. 这是工作选项。 I don't think there is a problem to hard code this.
我认为硬编码不存在问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.