【问题标题】:Symfony2: Unable to access the web directory from the entity classSymfony2:无法从实体类访问 web 目录
【发布时间】:2012-12-02 08:29:56
【问题描述】:

我正在尝试使用食谱示例来了解如何使用 symfony2 上传文件: http://symfony.com/doc/2.0/cookbook/doctrine/file_uploads.html

问题是我无法获取 web 文件夹的路径。

这里有一些细节:在我的网络文件夹中,我有这样的结构:

/web
    /bundles
        /sciforumversion2
            /images

从实体中,我尝试获取文件夹路径并将图像保存在 /images 文件夹中

为此,我正在使用:

protected function getUploadRootDir()
{
    // the absolute directory path where uploaded
    // documents should be saved
    return __DIR__ . '/../../../../web/'.$this->getUploadDir();
}

protected function getUploadDir()
{
    // get rid of the __DIR__ so it doesn't screw up
    // when displaying uploaded doc/image in the view.
    return 'sciforumversion2/bundles/images';
}

但是我得到了无法创建目录的异常:

Unable to create the "/home/milos/workspace/conference2.0/src/SciForum/Version2Bundle/Entity/../../../../web/sciforumversion2/bundles/images/conference" directory 

欢迎任何关于我如何获取网络文件夹 url 以及为什么 symfony 食谱提出的解决方案不起作用的想法。

非常感谢。 谢谢。

【问题讨论】:

  • 谢谢,但除了目录问题之外,我的个人捆绑包中的一切都在工作,所以我更喜欢使用我拥有的东西

标签: php symfony path doctrine-orm


【解决方案1】:

路径似乎是正确的。

也许你应该给它正确的权限。

先试试这个:

chmod 777 /home/milos/workspace/conference2.0/src/SciForum/Version2Bundle/Entity/../../../../web/sciforumversion2/bundles/images/

如果可行,那就是权限问题。 使用以下命令将所有者和组设置为 www-data:

chown www-data:www-data /home/milos/workspace/conference2.0/src/SciForum/Version2Bundle/Entity/../../../../web/sciforumversion2/bundles/images/
chmod 755 /home/milos/workspace/conference2.0/src/SciForum/Version2Bundle/Entity/../../../../web/sciforumversion2/bundles/images/

【讨论】:

  • 也就是说,它现在可以工作了,非常感谢。来自我的 +1,我已确认您的回答。
猜你喜欢
  • 2011-09-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-07-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多