Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    me'
    me' is offline
    Senior Coder
    Join Date
    Nov 2002
    Location
    Warwickshire, England
    Posts
    1,229
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Setting the mime type on an external file

    Okay. My CMS is nearly finished, but I have one problem. I want to create files that will contain individual blog posts, but I don't want these files to have extensions. Easy part: setting the mime type within the file. Hard part: getting the PHP code to run to actually change the mime type from text/plain to application/xhtml+xml.

    In other words, I load an extensionless file with something like this in in:
    Code:
    <?php
      header("Content-Type: application/xhtml+xml;");
    ?>
    Now, if I load this in a browser, the code will show, because the mime type is text/plain. The browser didn't think to execute the code to change the mime type, simply because it was served up as a text/plain file.

    So my question: can I (without giving the file an extension) set the mime type on a file I create?
    David House - Perfect is achieved, not when there is nothing left to add, but when there is nothing left to take away. (Antoine de St. Exupery).
    W3Schools | XHTML Validator | CSS Validator | Colours | Typography | HTML&CSS FAQ | Go get Mozilla Now | I blog!

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    Sheffield, UK
    Posts
    552
    Thanks
    0
    Thanked 0 Times in 0 Posts
    could you not call them .blog files or something, cos i been thinking about this and you can only tell apache to parse files with sertain extensions as PHP files, cant think how to do it without any extensions.
    "To be successful in IT you don't need to know everything - just where to find it in under 30 seconds"

    (Me Me Me Me Me Me Me Me Me)

  • #3
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You can use ForceType in a directory to get all files to be parsed as PHP, but it only works on Unix Apache, not Windows.

    Why do you need to the file to be extensionless?

    If content-negotiation is the point, then why not have master templates which include() the blog posts, then the includes don't have to have file extensions because they'll be parsed as part of the main page.

    If clean-URLs is the point, it's all much easier with mod_rewrite, then you can call them what you like on your end and the user will still see /path/to/article/
    Last edited by brothercake; 01-05-2004 at 09:52 PM.
    "Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark

  • #4
    me'
    me' is offline
    Senior Coder
    Join Date
    Nov 2002
    Location
    Warwickshire, England
    Posts
    1,229
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If clean-URLs is the point, it's all much easier with mod_rewrite, then you can call them what you like on your end and the user will still see /path/to/article/
    This sounds promising, but I've never heard of mod_rewrite. Is this a .htaccess thing?
    David House - Perfect is achieved, not when there is nothing left to add, but when there is nothing left to take away. (Antoine de St. Exupery).
    W3Schools | XHTML Validator | CSS Validator | Colours | Typography | HTML&CSS FAQ | Go get Mozilla Now | I blog!

  • #5
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    Yeah it's an htaccess and apache thang.

    http://www.phpfreaks.com/tutorials/23/0.php

  • #6
    me'
    me' is offline
    Senior Coder
    Join Date
    Nov 2002
    Location
    Warwickshire, England
    Posts
    1,229
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Originally posted by Nightfire
    Yeah it's an htaccess and apache thang.

    http://www.phpfreaks.com/tutorials/23/0.php
    thang eh? Dunno then... hmm...

    thanks for the ref.
    David House - Perfect is achieved, not when there is nothing left to add, but when there is nothing left to take away. (Antoine de St. Exupery).
    W3Schools | XHTML Validator | CSS Validator | Colours | Typography | HTML&CSS FAQ | Go get Mozilla Now | I blog!

  • #7
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts
    "Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark

  • #8
    me'
    me' is offline
    Senior Coder
    Join Date
    Nov 2002
    Location
    Warwickshire, England
    Posts
    1,229
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks.

    *curses the windows OS once again. .htaccess is a [word removed] file name!*
    David House - Perfect is achieved, not when there is nothing left to add, but when there is nothing left to take away. (Antoine de St. Exupery).
    W3Schools | XHTML Validator | CSS Validator | Colours | Typography | HTML&CSS FAQ | Go get Mozilla Now | I blog!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •