in reply to Download file to browser

When the browser requests https://www.my-website.com/download.pl?file=path1/path2/filename.ext , you need to respond with the Content-Disposition header. Depending on what way you use to send headers, this might need different code. For Mojolicious, you send headers like the following:

use File::Basename 'basename'; ... # Serve static file if it exists if (my $asset = $c->app->static->file('path1/path2/filename.ext')) { $c->res->headers->content_disposition('attachment; filename=filena +me.ext'); $c->reply->asset($asset); }

Replies are listed 'Best First'.
Re^2: Download file to browser
by david.woosley (Initiate) on Apr 19, 2024 at 16:47 UTC
    Hi Corion. What is the $c variable? Please understand that I'm novice Perl programmer. Thanks, David

      The $c variable is the context in Mojolicious. As you don't seem to be using Mojolicious, maybe you can tell us or even better show us the relevant parts of download.pl so we can better tell you how to add the header.

      Please understand that I'm novice Perl programmer. Any help will be appreciated.

      To take your novice Perl skills out of the equation, please take the time to read and understand the following non-Perl references:

      If you're then convinced of the merit of at least attempting to create a minimal reproducible example, have a go at doing that in Perl (you might find Short, Self-Contained, Correct Example useful in this endeavour). If you get stuck, please feel free to ask for assistance, we will be glad to help.

      Attempting to create a minimal reproducible example (even if unsuccessful) should have an added benefit of improving your general Perl skills and knowledge.

      👁️🍾👍🦟

        Nine thousand and seventy four times this. You’ve asked the programmer equivalent of, “Hey what’s the name of that movie? You know the one with that guy that wears a shirt?”

        The cake is a lie.
        The cake is a lie.
        The cake is a lie.