Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8921689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:36:52+00:00 2026-06-15T06:36:52+00:00

I have a link: {% for item in list %} … <a href={{ path(‘show’,

  • 0

I have a link:

    {% for item in list %}
        ...
        <a href="{{ path('show', { 'id': item.id }) }}"> read pdf file</a>
    {% endfor %}

When the user clicks the link I would like to show the pdf file (file stored as a blob in mysql). The code below is not correct, but I want my action to do something like following.

    /**
    * @Route("/show", name="show")
    */
    public function showAction()
    {
        $id = $this->get('request')->query->get('id');
        $item = $this->getDoctrine()->getRepository('MyDocsBundle:Files')->file($id);
        $pdfFile = $item->getFile(); //returns pdf file stored as mysql blob
        $response = new Response();
        $response->setStatusCode(200);
        $response->headers->set('Content-Type', 'application/pdf');
        $response->setContent($pdfFile);
        $response->send() //not sure if this is needed
        return $response;
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T06:36:53+00:00Added an answer on June 15, 2026 at 6:36 am

    I’m not sure Doctrine has a blob type natively, so I’ll assume you’ve got it setup to properly store the file as an actual BLOB in the database.

    Try something more along the lines of this…

    /**
    * @Route("/show/{id}", name="show")
    */
    public function showAction($id)
    {
        $item = $this->getDoctrine()->getRepository('MyDocsBundle:Files')->find($id);
        if (!$item) {
            throw $this->createNotFoundException("File with ID $id does not exist!");
        }
    
        $pdfFile = $item->getFile(); //returns pdf file stored as mysql blob
        $response = new Response($pdfFile, 200, array('Content-Type' => 'application/pdf'));
        return $response;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this markup: <ul><li id=link-notifications> <ul class=list-notifications style=display:none> <li><a href=/link/to>Item 1</a></li> </ul> </li>
I have this link in a template: <a href={% url show_item item.id %}>Item 1</a>
I have the following Nav: <li id=categories> <ul> <li class=cat-item cat-item-8 current-cat><a href=#>Link</a> <ul>
I have an ordered list, and each item has a link with class additem
I have a link in a page that goes like this: Url.Action(List, Item, new
I have the following xml <rss> <channel> <item><title><![CDATA[bla]]></title><description><![CDATA[desc1]]></description><link>blah</link></item> <item><title><![CDATA[bleh]]></title><description><![CDATA[desc2]]></description><link>blahhh</link></item> </rss> </channel> I want to
I have link that calls a function when clicked: <a href=javascript:spawnMenu(this); id=link1>Test1</a> To make
I have an unordered list with the following structure. If I click the link
I have a list of links that link to sections within the page using
I have next link that lets users navigate through a list of URL (stored

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.