上传的图像未显示Symfony2
我使用Symfony网站中文档提供的代码示例在Symfony2中创建了文件上载功能上传的图像未显示Symfony2,symfony,Symfony,我使用Symfony网站中文档提供的代码示例在Symfony2中创建了文件上载功能 public function getAbsolutePath() { return null === $this->path ? null : $this->getUploadRootDir().'/'.$this->path; } public function getWebPath() { return null === $this-&g
public function getAbsolutePath()
{
return null === $this->path
? null
: $this->getUploadRootDir().'/'.$this->path;
}
public function getWebPath()
{
return null === $this->path
? null
: $this->getUploadDir().'/'.$this->path;
}
protected function getUploadRootDir()
{
// the absolute directory path where uploaded
// documents should be saved
// return __DIR__.'/../../../../web/'.$this->getUploadDir();
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 'uploads/documents';
}
我可以上传一个文件,但twig无法显示它
<td><img src="/uploads/documents/{{ task.path }}" id="img-responsive"> </td>
在这种情况下,如何显示在Symfony中上载的图像
app
src
web
bundles
uploads
documents
return __DIR__.'/../../../../../web/'.$this->getUploadDir();
更新
路径保存在数据库中
path id
Desert.jpg 1
cat.jpg 2
dog.jpg 3
您可以使用DevDonkey建议,也可以像这样更改代码
<td><img src="yourhost.com/web/uploads/documents/{{ task.path }}" id="img-responsive"> </td>
这应该可以像我在当前项目中尝试和使用的那样工作。您可以使用DevDonkey建议,也可以像这样更改代码
<td><img src="yourhost.com/web/uploads/documents/{{ task.path }}" id="img-responsive"> </td>
这应该像我在当前项目中尝试和使用它一样有效。您应该真正使用twigs
{{asset()}}
方法。然后使用其中的路径和文件名。您应该真正使用twigs{{{asset()}
方法。然后使用其中的路径和文件名。
<td><img src="yourhost.com/web/uploads/documents/{{ task.path }}" id="img-responsive"> </td>