Bhavin Thummar
Bhavin Thummar

Reputation: 1293

Issue of getting image from web public folder in symfony

Hii Friends I have facing one problem in my virtually setup symfony project. When I want to try fetching image which is placed in web/uploads/images/ folder then i am getting this error. "No route found for "GET /uploads/images/2.jpeg".

Image for showing error message

My controller work is fine but problem is that i can't fetching any public file from web folder.

You can also check my virtual setup code in httpd-vhosts.conf

<VirtualHost *:80>
  DocumentRoot D:/XAMPP/htdocs/symphony/web/app_dev.php
  ServerName symphony.com
  <Directory D:/XAMPP/htdocs/symphony/web>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    allow from all
  </Directory>
</VirtualHost>

Check my file where i want get that image.

{% extends 'base.html.twig' %}

{% block body %}
<h2>Todo Edit</h2>
{{form_start(form)}}
{{form_widget(form)}}


<img src="{{ url('todo_list') }}uploads/images/2.jpeg" />

{{form_end(form)}}
{% endblock %}

Also check image for that file. Image of file where i am fetching image code.

Upvotes: 0

Views: 3646

Answers (1)

l13
l13

Reputation: 529

Please use assets:

{% image '@AppBundle/Resources/public/images/example.jpg' %}
   <img src="{{ asset_url }}" alt="Example" />
{% endimage %}

You can read here for more info: https://symfony.com/doc/3.3/frontend/assetic/asset_management.html

Upvotes: 1

Related Questions