简体   繁体   中英

How to set a filename for “Content-Disposition: inline;” file on android device?

Greeting.

There's a following set of header I use to process file being opened inline in browser window(usually it is PDF):

header("Content-Type: " . $mime[$ext]);
header("Content-Disposition: inline; filename=" . $path_parts["basename"]);
header("Content-length: $fsize");
header("Cache-control: private");

This code is placed in download.php file to achieve extra steps being done before file is actually thrown to client. Where uri to file is set as get variable like this:

http://sitedotcom/download.php?=file=path-to-file.pdf

And the problem is the following. Desktop opens file inline in browser window, but android device downloads it and set filename to download.php instead of path-to-file.pdf. This causes misunderstanding and am looking for help.

Is there a way to setup header somehow so that file gets a correct name?

Maybe you can use the apache module rewrite like this:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^pdf/([^/\.]+)$ download.php?file=$1 [L]
</IfModule>

The user will ask for:

http://sitedotcom/pdf/path-to-file.pdf

and the PHP will handle the URL

http://sitedotcom/download.php?file=path-to-file.pdf

So when the file will be saved it will be under "path-to-file.pdf"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM