简体   繁体   English

SonataMediaBundle:找不到文件/图像

[英]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界面上传图像时:

  1. Click on "Add New" ( app_dev.php/admin/sonata/media/media/create ) 点击“添加新”( app_dev.php/admin/sonata/media/media/create
  2. Click on "Image" ( 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
  3. Browse the image.jpg file and click on "create" 浏览image.jpg文件并单击“创建”
  4. This leads me to the edit page where I can see: Item "image.jpg" has been successfully created. 这导致我进入编辑页面,我可以看到: Item "image.jpg" has been successfully created.

And indeed: 事实上:

  • In the folder web\\uploads\\media\\default\\0001\\01 I have my image file and the 3 thumbs 在文件夹web\\uploads\\media\\default\\0001\\01我有我的图像文件和3个拇指
  • In the media__media DB table I have the corresponding line media__media数据库表中,我有相应的行
  • When I browse web/uploads/media/default/0001/01/ with Firefox I can see my image 当我使用Firefox浏览web/uploads/media/default/0001/01/ ,我可以看到我的图像
  • The corresponding line appears in the media list (in admin panel) 相应的行显示在媒体列表中(在管理面板中)

But : 但是

  • The image is not displayed in the media list (there is a square instead of the thumb) nor in the image edit page ( 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: 对于文件,情况更糟:

  1. Click on "Add New" ( app_dev.php/admin/sonata/media/media/create ) 点击“添加新”( app_dev.php/admin/sonata/media/media/create
  2. Click on "Image" ( 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
  3. Browse the 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_filesizepost_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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM