C
C
Captain Cocoa2016-11-03 20:01:14
PHP
Captain Cocoa, 2016-11-03 20:01:14

Forced download of a file instead of viewing it in the browser, how to do it?

Hello everyone, I need to force download files with the extension .7z on Wordpress.
There is such a trick, create a .htaccess file in the folder in which the files are located, and enter this into it.

<files *.7z>
  forceType application/octet-stream
  Header set Content-Disposition attachment
</files>

But the fact is that in Wordpress my folders are automatically created by date.
Is it possible to somehow correct this code so that it would be applied not only to the parent folder, but also to the child one.
For example, I created .htaccess in the uploads folder , but it will also apply to internal uploads/2016/11/file.7z

Answer the question

In order to leave comments, you need to log in

3 answer(s)
C
Captain Cocoa, 2017-05-15
@RadCor

The issue was resolved by writing the following line in the root .htaccess:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
AddType application/zip .zip .zip .7z

D
demorred, 2016-11-03
@demorred

And if you go by the method of adding to the download attribute link
htmlbook.ru/html/a/download

K
Kovalsky, 2016-11-03
@lazalu68

You can use JS - stackoverflow.com/questions/3077242/force-download...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question