mime_content_type() for PNG image returns "text/plain"

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • comp.lang.php

    #1

    mime_content_type() for PNG image returns "text/plain"

    PHP 4.3.8 with UNIX with option --with-magic_mime

    [PHP] echo mime_content_ty pe('/images/myimage.png'); // RETURNS
    "text/plain"[/PHP]

    PHP 4.3.11 with UNIX with option --with-magic_mime

    [PHP] echo mime_content_ty pe('/images/myimgae.png'); // RETURNS
    "text/plain"[/PHP]

    PHP 4.3.2 and 4.3.6 with UNIX, PHP 5.0.4 with Windows (w/o magic_mime
    support)

    [PHP] echo mime_content_ty pe('/images/myimage.png'); // RETURNS
    "image/png"[/PHP]

    I am having to shut off support within a portable web application that
    will be housed, at least, in the following environments:

    1. PHP 4.3.2/UNIX
    2. PHP 4.1.2/UNIX
    3. PHP 4.3.6/UNIX
    4. PHP 4.3.11/UNIX
    5. PHP 5.0.4/Windows

    this means that the environment must be universal for this to work, and
    in the case of a few test environments that were running 4.3.11 -
    5.0.4, mime_content_ty pe() under PHP supporting --with-magic_mime would
    always return
    text/plain
    and not
    image/png
    I think this is a bug but cannot independently verify this unless
    someone else here duplicates my test, provided they too are running PHP
    4.3.8+ with --with-magic_mime support enabled and see if they get the
    same results. Otherwise, how do I work around this problem? [Note: I
    wrote my own "mime_content_t ype()" function that works just fine)

    Thanx
    Phil

  • Erwin Moller

    #2
    Re: mime_content_ty pe() for PNG image returns "text/plain"

    comp.lang.php wrote:
    [color=blue]
    > PHP 4.3.8 with UNIX with option --with-magic_mime
    >
    > [PHP] echo mime_content_ty pe('/images/myimage.png'); // RETURNS
    > "text/plain"[/PHP]
    >
    > PHP 4.3.11 with UNIX with option --with-magic_mime
    >
    > [PHP] echo mime_content_ty pe('/images/myimgae.png'); // RETURNS
    > "text/plain"[/PHP]
    >
    > PHP 4.3.2 and 4.3.6 with UNIX, PHP 5.0.4 with Windows (w/o magic_mime
    > support)
    >
    > [PHP] echo mime_content_ty pe('/images/myimage.png'); // RETURNS
    > "image/png"[/PHP]
    >
    > I am having to shut off support within a portable web application that
    > will be housed, at least, in the following environments:
    >
    > 1. PHP 4.3.2/UNIX
    > 2. PHP 4.1.2/UNIX
    > 3. PHP 4.3.6/UNIX
    > 4. PHP 4.3.11/UNIX
    > 5. PHP 5.0.4/Windows
    >
    > this means that the environment must be universal for this to work, and
    > in the case of a few test environments that were running 4.3.11 -
    > 5.0.4, mime_content_ty pe() under PHP supporting --with-magic_mime would
    > always return
    text/plain
    and not
    >
    image/png
    >
    > I think this is a bug but cannot independently verify this unless
    > someone else here duplicates my test, provided they too are running PHP
    > 4.3.8+ with --with-magic_mime support enabled and see if they get the
    > same results. Otherwise, how do I work around this problem? [Note: I
    > wrote my own "mime_content_t ype()" function that works just fine)
    >
    > Thanx
    > Phil[/color]

    Hi

    did you try:
    // $f is path to file
    $f = escapeshellarg( $f);
    $mimetype = trim( `file -bi $f` );

    Maybe that works on all systems. (Not tested)

    Regards,
    Erwin Moller

    Comment

    • comp.lang.php

      #3
      Re: mime_content_ty pe() for PNG image returns "text/plain"

      I have that in my local "mime_content_t ype()" function I wrote. But
      because this version of PHP (4.3.11) comes with --with-magic_mime
      enabled, I am unable to use my version of "mime_content_t ype()" and am
      forced to use theirs.

      Phil

      Comment

      • comp.lang.php

        #4
        Re: mime_content_ty pe() for PNG image returns "text/plain"

        Oh one more thing, that does not work on Windows (don't know about Mac
        or Solaris), so I'm afraid it doesn't work on all systems. On Windows
        you're basically screwed and have to look at the ext and pray it's
        true-to-form.

        Phil

        Comment

        Working...