I have a .htaccess file set up to define specific MIME types in directory root/a/b/, and all of the files are in the same directory.
I have a php file that wants to serve those files, in directory root/c/, and needs to determine the content-type as defined by the .htaccess file.
Is there any way to do this? PHP version is 5.1.6. mime_content_type returns text/plain, and I’d rather not try to parse the .htaccess file manually. I can move the file if necessary.
if you want to serve the files with php, why don’t you also define the mime types with php (eg. as an associative array with extension => mime type pairs)?
that being said, a possible way to achieve this without parsing the .htaccess file would be to let the php script do a request for the file in
root/a/band check the mime type in the response headers. if you serve the files with the HTTP wrapper, eg.fopen('http://example.com/a/b/file'), you get this automatically: you can access the response headers via$http_response_headerorstream_get_meta_data– the mime type is in theContent-Type:header. if you open the file another way, you can still do a HEAD request first and check the response Content-Type (even though doing 2 requests for every file served seems overkill).