【发布时间】:2014-02-04 19:01:48
【问题描述】:
我正在学习 Symfony 2,但在 UploadedFile 类上遇到问题。 我想在我的项目中处理文件上传,所以感谢官方文档:How to handle File Uploads with Doctrine
效果很好。但是,它只在本地工作。我使用 MAMP 来测试我的项目。
我试图将我的项目放在 Debian 6 服务器中。 Symfony 应用程序可以工作,但上传文件不起作用。 当我使用 move() 方法移动文件时...出现此错误:
Unable to create the "/var/www/project/Symfony/src/project/Bundle/AlbumBundle/Entity/../../../../../web/images/postes_images" directory (500 Internal Server Error)
正如我告诉你的,它在本地运行良好。如果文件夹 postes_images 不存在,它应该自己创建。它在本地运行良好......
这是我的上传功能:
public function upload($indexPoste, $indexPic)
{
if (null === $this->file) {
return;
}
$this->name = "poste_".$indexPoste."_pic_".$indexPic;
$this->path = "poste_".$indexPoste."_pic_".$indexPic.".".$this->file->getClientOriginalExtension();
$this->file->move($this->getUploadRootDir(), $this->path);
$this->file = null;
}
获取路径的函数:
public function getUploadRootDir()
{
return __DIR__.'/../../../../../web/'.$this->getUploadDir();
}
protected function getUploadDir()
{
return 'images/postes_images';
}
路径是正确的,因为它在本地运行良好。我想知道这是否不是php配置的问题...... 我做了一些搜索,我在 move 方法中读到,如果文件夹不存在,他们会调用“mkdir”方法来创建文件夹......如果 mkdir 调用返回 false,它会返回我在上面放置的错误。
如果您知道如何解决此问题,请。我找不到任何东西。
谢谢
【问题讨论】:
-
这是服务器上的用户权限错误。您的 Web 用户没有足够的权限来创建目录。确保您的网络用户具有写入权限
-
这是我必须在 php 或 apache 中进行的配置吗?因为 symfony 2 的代码和我本地的完全一样……请问我在哪里可以为 web 用户的权限进行此配置? ://
标签: php symfony file-upload debian