O
O
Oleksandr2014-12-04 01:01:07
PHP
Oleksandr, 2014-12-04 01:01:07

How to restrict file download via direct link via httacess?

You need to restrict access to download the file.
Apache is on the server.
They don't want to install the XsendFile module.
It is not possible to download large files through php.
Here I sketched out such a method using the restriction through .httacess.
How to improve or suggest an alternative?
Thank you.

if( $logged_user ) {

          $htaccess = 'RewriteEngine Off\n';
          $htaccess .= '<FilesMatch "\.(zip)$">\n';
          $htaccess .= '	order deny,allow\n';
          $htaccess .= '	allow from ' . $_SERVER['REMOTE_ADDR'] .'\n';
          $htaccess .= '	deny from all\n';
          $htaccess .= '</FilesMatch>';
          file_put_contents($htaccess_file, $htaccess);

          header("Location: $url");
          header("Status: 303");
          exit();
        }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Hinex, 2014-12-04
@Track77

Hide the files in a directory and close access to it through ".htaccess". Give the files themselves through the interpreter.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question