Parse .txt as php + output mime type as text/plain

software development

#1

I’m trying to get plain text files parsed as .php files, but am not having much luck in also having that result returned as plain text to a browser via code.

Here is the setup so far within my DH acct :

cat .htaccess

RemoveHandler .txt .text
AddHandler php-cgi .txt .text

#<FilesMatch “.(t?xt)$”>
#AddType application/x-httpd-php .php .txt .text
#AddType application/php5-cgi .php .txt .text
#ForceType text/plain
#

and
head test.txt

<?php header("Content-Type: text/plain"); ?>

This is plain text to test.

However, when I try to set the content type within the top of the sample text file it does not seem to honor any of the header statements.

http://redbot.org/ shows this :

Content-Type: text/plain; charset=UTF-8

which looks great; it’s even running through gzip properly, etc.

However, actually browsing to the file yields

<?php header("Content-Type: text/plain"); ?>

This is plain text to test.

which is obviously not quite what I’m looking for.

I wish to keep detailed track of a few specific text files in a folder that could potentially be directly downloaded directly by URL. I will have whatever .htaccess statements are needed specified at that folder level.

The stats track program is written in php5, and is called via include. This works fine as a footer at the end of my standard site files, which all end in .php

Thanks for any pointers! :blush:

responses to this thread will be emailed to me, thanks.


#2

Simple case of trying too hard :wink:

.htaccess

AddHandler php5-cgi .txt .text

Customer since 2000 :cool: openvein.org


#3

Doh, that totally worked. I’d installed my own 5.2.9 / php.ini etc. and didn’t realize that I still need to go with the standard statements.

I’m pretty secure in my own areas (SAP and PeopleSoft) but this is “IT expansion time” and as always, so much to learn.

I left all the non-working in there on purpose of course, to show my “fail-trail”, though they were generally one at a time, just left in as comments after that :slight_smile:

Thanks for yet another solve. Re: OpenVein, sometimes it’s close to /wrists heh.

responses to this thread will be emailed to me, thanks.