Trouble with AddType application/x-httpd-php .png

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Kevin Blount

    #1

    Trouble with AddType application/x-httpd-php .png

    I'm trying to create the forum favorite dynamic sig image, that's
    realy PHP script. I've had moderate success with .php files but when I
    change the extension to .png I'm prompted to download the file, rather
    than it rendering.

    My understanding is that this is not supposed to happen, and that by
    adding an.htaccess file I can force .png files to be compiled/parsed/
    whatevered by PHP. In my .htaccess file I have:

    AddType application/x-httpd-php .png

    Any advice?

    I'm using heliohost.org as my host, and they basically pointed me to
    create the above file (as the first reply to my recent support query).
    Googling this I'm not seeing that I'm doing anything wrong.. so what
    gives?

  • Good Man

    #2
    Re: Trouble with AddType application/x-httpd-php .png

    "C. (http://symcbean.blogsp ot.com/)" <colin.mckinnon @gmail.comwrote in
    news:1193403723 .633067.95850@o 3g2000hsb.googl egroups.com:

    2) set the content type for the browser to use in a header(...) call
    in your PHP
    that is absolutely the way to go. don't mess with apache at all, use

    <img src="imageDispl ay.php?key=3947 8197">

    and have imageDisplay.ph p use:

    header("Content-type: image/png");
    $im = imagecreatefrom png("test.png") ;
    imagepng($im);




    Comment

    • Rik Wasmus

      #3
      Re: Trouble with AddType application/x-httpd-php .png

      On Fri, 26 Oct 2007 16:31:44 +0200, Good Man <heyho@letsgo.c omwrote:
      "C. (http://symcbean.blogsp ot.com/)" <colin.mckinnon @gmail.comwrote in
      news:1193403723 .633067.95850@o 3g2000hsb.googl egroups.com:
      >
      >
      >2) set the content type for the browser to use in a header(...) call
      >in your PHP
      >
      that is absolutely the way to go. don't mess with apache at all, use
      >
      <img src="imageDispl ay.php?key=3947 8197">
      >
      and have imageDisplay.ph p use:
      >
      header("Content-type: image/png");
      $im = imagecreatefrom png("test.png") ;
      imagepng($im);
      Hmm, that would be unneccessary. Unless you plan to alter the picture,
      just do a header & a readfile('test. png'); Tremendously saves memory usage.
      --
      Rik Wasmus

      Comment

      • Brendan Gillatt

        #4
        Re: Trouble with AddType application/x-httpd-php .png

        -----BEGIN PGP SIGNED MESSAGE-----
        Hash: SHA1

        Kevin Blount wrote:
        I'm trying to create the forum favorite dynamic sig image, that's
        realy PHP script. I've had moderate success with .php files but when I
        change the extension to .png I'm prompted to download the file, rather
        than it rendering.
        >
        My understanding is that this is not supposed to happen, and that by
        adding an.htaccess file I can force .png files to be compiled/parsed/
        whatevered by PHP. In my .htaccess file I have:
        >
        AddType application/x-httpd-php .png
        >
        Any advice?
        >
        I'm using heliohost.org as my host, and they basically pointed me to
        create the above file (as the first reply to my recent support query).
        Googling this I'm not seeing that I'm doing anything wrong.. so what
        gives?
        >
        I agree with the second poster - I don't think you can change the types
        with .htaccess. You could try using mod_rewrite to direct everything from
        , say, "/image-12345.png" to "image.php?id=1 2345". I'm not great with
        regular expressions but I'm sure someone else can help you out with that.

        - --
        Brendan Gillatt
        brendan {at} brendangillatt {dot} co {dot} uk

        PGP Key: http://pgp.mit.edu:11371/pks/lookup?...rch=0xBACD7433
        -----BEGIN PGP SIGNATURE-----
        Version: GnuPG v1.4.3 (MingW32)

        iD8DBQFHIf8FkA9 dCbrNdDMRAj/RAJ4sTogymJHcE9 q+u8qNVKohnCWwI gCg2pJk
        kA8IGylIajuEVPq 2oB5JQSE=
        =Brkz
        -----END PGP SIGNATURE-----

        Comment

        • Good Man

          #5
          Re: Trouble with AddType application/x-httpd-php .png

          "Rik Wasmus" <luiheidsgoeroe @hotmail.comwro te in
          news:op.t0s6ykd v5bnjuv@metalli um.lan:
          On Fri, 26 Oct 2007 16:31:44 +0200, Good Man <heyho@letsgo.c omwrote:
          >
          >"C. (http://symcbean.blogsp ot.com/)" <colin.mckinnon @gmail.comwrote
          in
          >news:119340372 3.633067.95850@ o3g2000hsb.goog legroups.com:
          >>
          >>
          >>2) set the content type for the browser to use in a header(...) call
          >>in your PHP
          >>
          >that is absolutely the way to go. don't mess with apache at all, use
          >>
          ><img src="imageDispl ay.php?key=3947 8197">
          >>
          >and have imageDisplay.ph p use:
          >>
          >header("Conten t-type: image/png");
          >$im = imagecreatefrom png("test.png") ;
          >imagepng($im );
          >
          Hmm, that would be unneccessary. Unless you plan to alter the picture,
          just do a header & a readfile('test. png'); Tremendously saves memory
          usage.
          good one.

          Comment

          • Kevin Blount

            #6
            Re: Trouble with AddType application/x-httpd-php .png

            On Oct 26, 11:17 am, Good Man <he...@letsgo.c omwrote:
            "Rik Wasmus" <luiheidsgoe... @hotmail.comwro te innews:op.t0s6y kdv5bnjuv@metal lium.lan:
            >
            >
            >
            >
            >
            On Fri, 26 Oct 2007 16:31:44 +0200, Good Man <he...@letsgo.c omwrote:
            >
            "C. (http://symcbean.blogsp ot.com/)" <colin.mckin... @gmail.comwrote
            in
            >news:119340372 3.633067.95850@ o3g2000hsb.goog legroups.com:
            >
            >2) set the content type for the browser to use in a header(...) call
            >in your PHP
            >
            that is absolutely the way to go. don't mess with apache at all, use
            >
            <img src="imageDispl ay.php?key=3947 8197">
            >
            and have imageDisplay.ph p use:
            >
            header("Content-type: image/png");
            $im = imagecreatefrom png("test.png") ;
            imagepng($im);
            >
            Hmm, that would be unneccessary. Unless you plan to alter the picture,
            just do a header & a readfile('test. png'); Tremendously saves memory
            usage.
            >
            good one.- Hide quoted text -
            >
            - Show quoted text -
            Thanks all for the responses. It's much appreciated.

            Here's what I ended up using:


            AddType application/x-httpd-php .png
            RewriteEngine On
            RewriteRule .png /phpsigs/create-sig.php


            basically just redirects all .PNG requests to a single PHP script, I
            can then grab the file name, etc and personalize the image being
            returned.

            With thankful regards,

            BK

            Comment

            • Rik Wasmus

              #7
              Re: Trouble with AddType application/x-httpd-php .png

              On Fri, 26 Oct 2007 23:39:14 +0200, Kevin Blount <kevin.blount@g mail.com>
              wrote:
              AddType application/x-httpd-php .png
              RewriteEngine On
              RewriteRule .png /phpsigs/create-sig.php
              >
              >
              basically just redirects all .PNG requests to a single PHP script, I
              can then grab the file name, etc and personalize the image being
              returned.
              Hmm, either parse png's for code, or rewrite the url's. Doing both is just
              silly, so I'd lose the AddType...
              --
              Rik Wasmus

              Comment

              • AnrDaemon

                #8
                Re: Trouble with AddType application/x-httpd-php .png

                Greetings, Kevin Blount.
                In reply to Your message dated Saturday, October 27, 2007, 01:39:14,

                KBAddType application/x-httpd-php .png

                Useless.

                KBRewriteEngine On
                KBRewriteRule .png /phpsigs/create-sig.php

                You forgot [QSA] flag. (Query String Append)

                So,

                RewriteEngine On
                RewriteRule \.png$ /phpsigs/create-sig.php [QSA,L]

                KBbasically just redirects all .PNG requests to a single PHP script, I
                KBcan then grab the file name, etc and personalize the image being
                KBreturned.


                --
                Sincerely Yours, AnrDaemon <anrdaemon@free mail.ru>

                Comment

                • Kevin Blount

                  #9
                  Re: Trouble with AddType application/x-httpd-php .png

                  On Oct 27, 2:43 am, AnrDaemon <anrdae...@free mail.ruwrote:
                  Greetings, Kevin Blount.
                  In reply to Your message dated Saturday, October 27, 2007, 01:39:14,
                  >
                  KBAddType application/x-httpd-php .png
                  >
                  Useless.
                  >
                  KBRewriteEngine On
                  KBRewriteRule .png /phpsigs/create-sig.php
                  >
                  You forgot [QSA] flag. (Query String Append)
                  >
                  So,
                  >
                  RewriteEngine On
                  RewriteRule \.png$ /phpsigs/create-sig.php [QSA,L]
                  >
                  KBbasically just redirects all .PNG requests to a single PHP script, I
                  KBcan then grab the file name, etc and personalize the image being
                  KBreturned.
                  >
                  --
                  Sincerely Yours, AnrDaemon <anrdae...@free mail.ru>
                  Thanks both.

                  I did lose the AddType in the end, but didn't know about [QSA,L] -
                  what does that do? seems to work ok without it, but would be good to
                  know what it's for.

                  Cheers

                  Comment

                  • Jerry Stuckle

                    #10
                    Re: Trouble with AddType application/x-httpd-php .png

                    Kevin Blount wrote:
                    On Oct 27, 2:43 am, AnrDaemon <anrdae...@free mail.ruwrote:
                    >Greetings, Kevin Blount.
                    >In reply to Your message dated Saturday, October 27, 2007, 01:39:14,
                    >>
                    >KBAddType application/x-httpd-php .png
                    >>
                    >Useless.
                    >>
                    >KBRewriteEngin e On
                    >KBRewriteRul e .png /phpsigs/create-sig.php
                    >>
                    >You forgot [QSA] flag. (Query String Append)
                    >>
                    >So,
                    >>
                    >RewriteEngin e On
                    >RewriteRule \.png$ /phpsigs/create-sig.php [QSA,L]
                    >>
                    >KBbasically just redirects all .PNG requests to a single PHP script, I
                    >KBcan then grab the file name, etc and personalize the image being
                    >KBreturned.
                    >>
                    >--
                    >Sincerely Yours, AnrDaemon <anrdae...@free mail.ru>
                    >
                    Thanks both.
                    >
                    I did lose the AddType in the end, but didn't know about [QSA,L] -
                    what does that do? seems to work ok without it, but would be good to
                    know what it's for.
                    >
                    Cheers
                    >
                    >
                    Try alt.apache.conf iguration. They can show you the correct way to do it.

                    --
                    =============== ===
                    Remove the "x" from my email address
                    Jerry Stuckle
                    JDS Computer Training Corp.
                    jstucklex@attgl obal.net
                    =============== ===

                    Comment

                    • Michael Fesser

                      #11
                      Re: Trouble with AddType application/x-httpd-php .png

                      ..oO(Kevin Blount)
                      >I did lose the AddType in the end, but didn't know about [QSA,L] -
                      >what does that do? seems to work ok without it, but would be good to
                      >know what it's for.


                      Micha

                      Comment

                      • Rik Wasmus

                        #12
                        Re: Trouble with AddType application/x-httpd-php .png

                        On Sat, 27 Oct 2007 21:58:25 +0200, Kevin Blount <kevin.blount@g mail.com>
                        wrote:
                        On Oct 27, 2:43 am, AnrDaemon <anrdae...@free mail.ruwrote:
                        >Greetings, Kevin Blount.
                        >In reply to Your message dated Saturday, October 27, 2007, 01:39:14,
                        >>
                        >KBAddType application/x-httpd-php .png
                        >>
                        >Useless.
                        >>
                        >KBRewriteEngin e On
                        >KBRewriteRul e .png /phpsigs/create-sig.php
                        >>
                        >You forgot [QSA] flag. (Query String Append)
                        >>
                        >So,
                        >>
                        >RewriteEngin e On
                        >RewriteRule \.png$ /phpsigs/create-sig.php [QSA,L]
                        >>
                        >KBbasically just redirects all .PNG requests to a single PHP script, I
                        >KBcan then grab the file name, etc and personalize the image being
                        >KBreturned.
                        >>
                        >
                        I did lose the AddType in the end, but didn't know about [QSA,L] -
                        what does that do? seems to work ok without it, but would be good to
                        know what it's for.
                        Hmm, you'd think when doing rewrites one would consult the manual.



                        See 'Flags'.
                        --
                        Rik Wasmus

                        Comment

                        • 4sak3n 0ne

                          #13
                          Re: Trouble with AddType application/x-httpd-php .png

                          On Oct 27, 12:58 pm, Kevin Blount <kevin.blo...@g mail.comwrote:
                          On Oct 27, 2:43 am, AnrDaemon <anrdae...@free mail.ruwrote:
                          >
                          >
                          >
                          Greetings, Kevin Blount.
                          In reply to Your message dated Saturday, October 27, 2007, 01:39:14,
                          >
                          KBAddType application/x-httpd-php .png
                          >
                          Useless.
                          >
                          KBRewriteEngine On
                          KBRewriteRule .png /phpsigs/create-sig.php
                          >
                          You forgot [QSA] flag. (Query String Append)
                          >
                          So,
                          >
                          RewriteEngine On
                          RewriteRule \.png$ /phpsigs/create-sig.php [QSA,L]
                          >
                          KBbasically just redirects all .PNG requests to a single PHP script, I
                          KBcan then grab the file name, etc and personalize the image being
                          KBreturned.
                          >
                          --
                          Sincerely Yours, AnrDaemon <anrdae...@free mail.ru>
                          >
                          Thanks both.
                          >
                          I did lose the AddType in the end, but didn't know about [QSA,L] -
                          what does that do? seems to work ok without it, but would be good to
                          know what it's for.
                          >
                          Cheers
                          AddType defines the mime type of file extensions. mime types are how
                          the server knows the difference between images, plain text and other
                          files. This information also carries over to the browser so it is
                          able to display the information correctly.

                          I believe the original problem was that AddType image/png .png
                          occurred before you told Apache to parse it as php. I gather that it
                          defaulted to the first one defined.

                          In any case, defining the content type from within PHP is the best
                          option in this case. It prevents real pngs from being parsed as php.

                          Comment

                          Working...