Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

.htaccess and <filesmatch> directive

Status
Not open for further replies.

BlindPete

Programmer
Jul 5, 2000
711
US
Hello All,

I'm stumped and very new htaccess files.

I have a folder tree. At the top of this tree is an .htaccess that contains only:
Code:
<FilesMatch &quot;\.(wdb)$&quot; >
ForceType application/octet-stream
</FilesMatch>
The purpose is to force files of this type to download rather then display in the browser. However it only works in the same file as the htaccess file how do I make it cascade to all the sub directories? or am I going about this all wronge?

-Pete
Do you get a little guilty pleasure when a celebrity has a bad day?
Well then The Dead Pool is for you!
 
As it turns out the sever had a different name for files then .htaccess

After much consideration and further research I decided the most portable solution was to use the header() force my download as page attachment.

I used code from PHP.net as my starting point I found I needed to make some additional adjustments to insure compatablity with the customers browser but all in all I am please with result.

Code:
$filename=&quot;&quot;; // the name the file will have on client computer
$file_to_download=&quot;&quot;; // the name the file has on the server (or an FTP or HTTP request)
$user_agent = strtolower ($_SERVER[&quot;HTTP_USER_AGENT&quot;]);
header( &quot;Content-type: application/force-download&quot; );
if ((is_integer (strpos($user_agent, &quot;msie&quot;))) && (is_integer (strpos($user_agent, &quot;win&quot;)))) {
  header( &quot;Content-Disposition: filename=&quot;.$filename);
} else {
  header( &quot;Content-Disposition: attachment; filename=&quot;$filename);
}
header( &quot;Content-Description: File Transfert&quot;);
@readfile($file_to_download);

-Pete
Do you get a little guilty pleasure when a celebrity has a bad day?
Well then The Dead Pool is for you!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top