Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I want to post a .h file from a project I'm working on. I set a simple href link to it, like:

<p>Click here to download the <a href=project_strings.h>strings file</a>.

When I click on it, though, my web browser (Iceweasel 12) gives me a prompt to download the file, instead of just displaying it:

enter image description here

Is there any magic I can add to the web page, or as a header to the file (that will still allow it to be included by a .c compiled with gcc), to get the .h file to be displayed in the web browser?

share|improve this question
    
So, funny story: I realized this was a problem at the 11th hour, freaked out, frantically asked this question, made the change... and of the 6k visitors I've gotten, only 26 clicked on that link. sigH –  drewbenn Jun 7 '12 at 7:58

2 Answers 2

up vote 5 down vote accepted

If the file is served by an HTTP server (web server), check that it is sent with the header Content-Type: text/plain (and, if needed, modify server settings to achieve that). To check the headers, use e.g. http://web-sniffer.net.

Otherwise, you could set type="text/plain" on the linking element, i.e.

<a href=project_strings.h type="text//plain">strings file</a>

though the odds are that this has no effect.

That’s pretty much what you can do as an author. The rest is up to the browser and its settings.

share|improve this answer
1  
Nope, didn't work, but you pointed me in the right direction: I'm using Apache hosted by someone else (probably should've mentioned that, huh?) and I just needed to add a line "AddType text/plain .h" to the .htaccess file in the root of my server. So thanks! –  drewbenn Jun 5 '12 at 5:20

The problem is that your webserver doesn't know what to do with a .h file, so you need to tell it what mime-type to use.

Add the following line to your .htaccess file:

AddType text/plain h

And your browser will be able to load the file rather than downloading it.

You can also do this through httpd.conf:-

<IfModule mod_mime.c>
AddType text/plain .h
</IfModule>

The same applies to IIS, though obviously you'd need to find out how to add the appropriate code.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.