How do I link to a downloadable file in CakePHP 3.6?









up vote
0
down vote

favorite












How do I link to a downloadable file in CakePHP 3.6? The file is webroot/files/filename.pdf



I can create the link using



$this->Html->link('Link text', '/files/filename.pdf');


but when I click on it, I get the message "FilesController could not be found.".



I've searched the documentation and online, but can't find any mention of this.










share|improve this question



















  • 1




    Is the file really at /files/filename.pdf? The message indicates that the file could not be found and therefore the app tries to apply the standard controller/action fallback route it, just to discover that this controller does not exist either.
    – David Albrecht
    Oct 17 at 15:08










  • Thank you! You were right - I had saved it with a different name on the fileserver! Can't believe it was something so simple, but I'll leave this here in case it helps anyone else at a later stage. Thanks again.
    – Sharon
    Oct 17 at 19:18














up vote
0
down vote

favorite












How do I link to a downloadable file in CakePHP 3.6? The file is webroot/files/filename.pdf



I can create the link using



$this->Html->link('Link text', '/files/filename.pdf');


but when I click on it, I get the message "FilesController could not be found.".



I've searched the documentation and online, but can't find any mention of this.










share|improve this question



















  • 1




    Is the file really at /files/filename.pdf? The message indicates that the file could not be found and therefore the app tries to apply the standard controller/action fallback route it, just to discover that this controller does not exist either.
    – David Albrecht
    Oct 17 at 15:08










  • Thank you! You were right - I had saved it with a different name on the fileserver! Can't believe it was something so simple, but I'll leave this here in case it helps anyone else at a later stage. Thanks again.
    – Sharon
    Oct 17 at 19:18












up vote
0
down vote

favorite









up vote
0
down vote

favorite











How do I link to a downloadable file in CakePHP 3.6? The file is webroot/files/filename.pdf



I can create the link using



$this->Html->link('Link text', '/files/filename.pdf');


but when I click on it, I get the message "FilesController could not be found.".



I've searched the documentation and online, but can't find any mention of this.










share|improve this question















How do I link to a downloadable file in CakePHP 3.6? The file is webroot/files/filename.pdf



I can create the link using



$this->Html->link('Link text', '/files/filename.pdf');


but when I click on it, I get the message "FilesController could not be found.".



I've searched the documentation and online, but can't find any mention of this.







cakephp-3.0






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 10 at 20:09









halfer

14.2k757105




14.2k757105










asked Oct 17 at 11:37









Sharon

84462549




84462549







  • 1




    Is the file really at /files/filename.pdf? The message indicates that the file could not be found and therefore the app tries to apply the standard controller/action fallback route it, just to discover that this controller does not exist either.
    – David Albrecht
    Oct 17 at 15:08










  • Thank you! You were right - I had saved it with a different name on the fileserver! Can't believe it was something so simple, but I'll leave this here in case it helps anyone else at a later stage. Thanks again.
    – Sharon
    Oct 17 at 19:18












  • 1




    Is the file really at /files/filename.pdf? The message indicates that the file could not be found and therefore the app tries to apply the standard controller/action fallback route it, just to discover that this controller does not exist either.
    – David Albrecht
    Oct 17 at 15:08










  • Thank you! You were right - I had saved it with a different name on the fileserver! Can't believe it was something so simple, but I'll leave this here in case it helps anyone else at a later stage. Thanks again.
    – Sharon
    Oct 17 at 19:18







1




1




Is the file really at /files/filename.pdf? The message indicates that the file could not be found and therefore the app tries to apply the standard controller/action fallback route it, just to discover that this controller does not exist either.
– David Albrecht
Oct 17 at 15:08




Is the file really at /files/filename.pdf? The message indicates that the file could not be found and therefore the app tries to apply the standard controller/action fallback route it, just to discover that this controller does not exist either.
– David Albrecht
Oct 17 at 15:08












Thank you! You were right - I had saved it with a different name on the fileserver! Can't believe it was something so simple, but I'll leave this here in case it helps anyone else at a later stage. Thanks again.
– Sharon
Oct 17 at 19:18




Thank you! You were right - I had saved it with a different name on the fileserver! Can't believe it was something so simple, but I'll leave this here in case it helps anyone else at a later stage. Thanks again.
– Sharon
Oct 17 at 19:18












2 Answers
2






active

oldest

votes

















up vote
1
down vote













You need to pass the download attribute in your anchor tag. For cakephp 3, you can pass it something like



$this->Html->link('Link text', '/files/filename.pdf',['download'=>'filename.pdf']);


or



$this->Html->link('Link text', '/files/filename.pdf',array('download'=>'filename.pdf'));





share|improve this answer




















  • Thank you! That's helpful to know!
    – Sharon
    Oct 25 at 19:54

















up vote
0
down vote



accepted










Thanks to David, I realised I was doing the right things as far as Cake was concerned, but was using the wrong file name and linking to a file that didn't exist on the server.






share|improve this answer




















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52853973%2fhow-do-i-link-to-a-downloadable-file-in-cakephp-3-6%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    1
    down vote













    You need to pass the download attribute in your anchor tag. For cakephp 3, you can pass it something like



    $this->Html->link('Link text', '/files/filename.pdf',['download'=>'filename.pdf']);


    or



    $this->Html->link('Link text', '/files/filename.pdf',array('download'=>'filename.pdf'));





    share|improve this answer




















    • Thank you! That's helpful to know!
      – Sharon
      Oct 25 at 19:54














    up vote
    1
    down vote













    You need to pass the download attribute in your anchor tag. For cakephp 3, you can pass it something like



    $this->Html->link('Link text', '/files/filename.pdf',['download'=>'filename.pdf']);


    or



    $this->Html->link('Link text', '/files/filename.pdf',array('download'=>'filename.pdf'));





    share|improve this answer




















    • Thank you! That's helpful to know!
      – Sharon
      Oct 25 at 19:54












    up vote
    1
    down vote










    up vote
    1
    down vote









    You need to pass the download attribute in your anchor tag. For cakephp 3, you can pass it something like



    $this->Html->link('Link text', '/files/filename.pdf',['download'=>'filename.pdf']);


    or



    $this->Html->link('Link text', '/files/filename.pdf',array('download'=>'filename.pdf'));





    share|improve this answer












    You need to pass the download attribute in your anchor tag. For cakephp 3, you can pass it something like



    $this->Html->link('Link text', '/files/filename.pdf',['download'=>'filename.pdf']);


    or



    $this->Html->link('Link text', '/files/filename.pdf',array('download'=>'filename.pdf'));






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Oct 25 at 9:40









    Rafi Ahmad

    253




    253











    • Thank you! That's helpful to know!
      – Sharon
      Oct 25 at 19:54
















    • Thank you! That's helpful to know!
      – Sharon
      Oct 25 at 19:54















    Thank you! That's helpful to know!
    – Sharon
    Oct 25 at 19:54




    Thank you! That's helpful to know!
    – Sharon
    Oct 25 at 19:54












    up vote
    0
    down vote



    accepted










    Thanks to David, I realised I was doing the right things as far as Cake was concerned, but was using the wrong file name and linking to a file that didn't exist on the server.






    share|improve this answer
























      up vote
      0
      down vote



      accepted










      Thanks to David, I realised I was doing the right things as far as Cake was concerned, but was using the wrong file name and linking to a file that didn't exist on the server.






      share|improve this answer






















        up vote
        0
        down vote



        accepted







        up vote
        0
        down vote



        accepted






        Thanks to David, I realised I was doing the right things as far as Cake was concerned, but was using the wrong file name and linking to a file that didn't exist on the server.






        share|improve this answer












        Thanks to David, I realised I was doing the right things as far as Cake was concerned, but was using the wrong file name and linking to a file that didn't exist on the server.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Oct 17 at 19:18









        Sharon

        84462549




        84462549



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52853973%2fhow-do-i-link-to-a-downloadable-file-in-cakephp-3-6%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            這個網誌中的熱門文章

            How to read a connectionString WITH PROVIDER in .NET Core?

            In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

            Museum of Modern and Contemporary Art of Trento and Rovereto