1

When using Symfony 1.0, is it possible to create a link to a static file i.e. a PDF or DOC file and link to it a custom URL?

I'd like to add a file e.g. example.pdf to the web/uploads/pdf folder on the server but then link to it with a URL such as: http://www.example.com/docs/old/test/example.pdf

This situation has arisen because some printed documentation from before the development of a new web site points to the specified URL.

1 Answer 1

2

Ok, I have figured it out (with a great deal of help from this blog post. Thanks Thaberkern)

Create a route to grab the file name:

legacy_docs:
  url: /docs/:filename.pdf
  param: { module: default, action: display_pdf }

Then create an action to output the pdf:

  public function executeDisplayPdf()
  {
    $filename = $this->getRequestParameter('filename');

    $path_to_pdf = 'http://'.sfConfig::get('website_hostname').'/uploads/'.'/'.$filename.'.pdf';

    //create the response object
    $this->getResponse()->clearHttpHeaders();
    $this->getResponse()->setHttpHeader('Pragma: public', true);
    $this->getResponse()->setContentType('application/pdf');
    $this->getResponse()->sendHttpHeaders();
    $this->getResponse()->setContent(readfile($path_to_pdf));

    //set up the view
    $this->setLayout(false);
    sfConfig::set('sf_web_debug', false);

    return sfView::NONE;
  }
Sign up to request clarification or add additional context in comments.

1 Comment

Glad to see that the blog entry was helpful :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.