Force "File Save As" like X-Sendfile feature?

Discussion in 'Install/Configuration' started by Crazy Serb, Oct 23, 2016.

  1. Crazy Serb

    Crazy Serb Member

    Ok, I've looked everywhere and I can't figure out how to do this in Litespeed.

    In Apache, I can easily enable this module:

    And have files forced to download when referenced/called via the browser's "Save As" feature.

    And everywhere I look people are pointing out to this implementation in Litespeed of the same feature:

    But it's nowhere near the same, or it doesn't work the same way - it just opens up the file referenced, doesn't allow me to force "Save As" option on it.

    Here is what I have in my download.php file (that worked just fine on Apache):

    $file= $_GET["path"];
    header("X-LiteSpeed-Location: /media/$file");
    header("Content-Type: application/octet-stream");
    header("Content-Disposition: attachment; filename=\"$file\"");

    And the file is called with download.php?path=Filename.pdf

    What am I missing?

    Or what is Litespeed missing to force this as a downloadable file instead?
  2. NiteWave

    NiteWave Administrator

    I did local tests, can partially reproduce the issue. however following code works:

    $file= $_GET["path"];
    header("Content-Type: application/octet-stream");
    header("Content-Disposition: attachment; filename=\"../media/$file\"");

    i.e., just don't use X-LiteSpeed-Location header.

    by my quick tests, it looks if you use X-LiteSpeed-Location, then other headers
    header("Content-Type: application/octet-stream");
    header("Content-Disposition: attachment; filename=\"$file\"");
    will be missing. hence browser will open the pdf file instead of download it.
  3. Crazy Serb

    Crazy Serb Member

    Well, I can't get even that to work properly - to force downloading a specific file, let alone with the X-LiteSpeed-Location header. I just get an empty/corrupted file.

    So why is that X-LiteSpeed-Location header even mentioned and documented/suggested if it doesn't work as expected... assuming it was supposed to work the way I expected it.
  4. NiteWave

    NiteWave Administrator

    X-LiteSpeed-Location is good feature and I've tested it in production server. it's just not needed in your this case.

    I can help you to get it working if you give the access to the server.
  5. mistwang

    mistwang LiteSpeed Staff

    Please upgrade to latest 5.1.15 with command
    /usr/local/lsws/admin/misc/ -f -v 5.1.15

    There is a related bug introduced in earlier build of 5.1.15, fixed.

Share This Page