Reputation: 6042
I made a simple little image upload page in my Symfony project following these docs. The file uploads work fine after setting the permissions to the destination directory to 777. Unfortunately, when I attempt to display the uploaded images in a gallery, they won't display, and Apache 2 gives me a 'not found' error.
The web path of the images is dynamically generated by my GalleryImage
entity:
public function getWebPath()
{
return null === $this->path ? null : $this->getUploadRootDir() . '/' . $this->path;
}
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 'uploads/gallery';
}
In my view (twig), I attempt to display them with the following:
<a href="{{ image.webPath }}" data-lightbox="gallery"><img src="{{ asset(image.webPath) }}" class="gallery-thumb"></a>
Which generates markup that looks like:
<a href="/home/kevin/www/diva/src/MajorProductions/SewingDiva/SiteBundle/Entity/../../../../../web/uploads/gallery/d15728da272656a4ab0e670f589ee033e43494d6.jpeg" data-lightbox="gallery"><img src="/home/kevin/www/diva/src/MajorProductions/SewingDiva/SiteBundle/Entity/../../../../../web/uploads/gallery/d15728da272656a4ab0e670f589ee033e43494d6.jpeg" class="gallery-thumb"></a>
But, when I attempt to access them, it tells me:
The requested URL /home/kevin/www/diva/web/uploads/gallery/d15728da272656a4ab0e670f589ee033e43494d6.jpeg was not found on this server
Even though, again, the destination directory has 777 for its permissions, and I can see the images there in the file system.
Any ideas why it's telling me my images can't be found?
Upvotes: 0
Views: 915
Reputation: 2049
I had the same problem, and this works for me:
<a href="{{ asset('uploads/gallery/') }}{{image.path}}" data-lightbox="gallery"><img src="{{ asset('uploads/gallery/') }}{{image.path}}" class="gallery-thumb"></a>
Upvotes: 1