Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Jan 2003
    Thanked 0 Times in 0 Posts

    Getting mime-type from file (or its .ext)

    I am pretty sure this can be done as it is mentioed in the docs (but as always, it talks mainly about UNIX !!)
    Is there a built-in function that will return the mime-type in the form "text/plain" based upon the filedata or extension of a file on the server.
    I have tried the mime_content_type(String filename) function, but an undefined function error is returned when i try to use it on my win32 system.

    Failing the existance of a built in function, how easy would it be to write one, assuming the default file extensions for all mime types??

    <?XML version="1.0" standalone="Yes" encoding="utf-8"?>
    XML is the future - embrace it

  2. #2
    Regular Coder
    Join Date
    Sep 2002
    British Columbia
    Thanked 0 Times in 0 Posts
    If nothing else you could make an array of all MIME types (or at least all the ones you need to deal with), and do something like this:

    PHP Code:
    $allcontenttypes = array(
    'png' => 'image/png',
    'pdf' => 'application/pdf'

    $fileextension substr($filename, -3);

    $contenttype $allcontenttypes[$fileextension]; 


Posting Permissions

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