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

Crazy Serb

Well-Known Member
#1
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:

https://tn123.org/mod_xsendfile/

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:

https://www.litespeedtech.com/support/wiki/doku.php/litespeed_wiki:config:internal-redirect

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?
 

NiteWave

Administrator
#2
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.
 

Crazy Serb

Well-Known Member
#3
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.
 

NiteWave

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

Well, I can't get even that to work properly - to force downloading a specific file
I can help you to get it working if you give the access to the server.
 

mistwang

LiteSpeed Staff
#5
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.
Please upgrade to latest 5.1.15 with command
/usr/local/lsws/admin/misc/lsup.sh -f -v 5.1.15

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