Sagewire Logo

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

14 Message(s) by 9 Author(s) originally posted in php programming


From: Kevin Blount Date:   Friday, October 26, 2007
I'm trying to create the forum favorite dynamic sig image , that's
real y PHP script. I have had moderate success with .php file s but when I
change the extension to .png I'm prompted to download the file, rather
than it rendering.

My understanding is that this isn't 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?


From: AnrDaemon Date:   Friday, October 26, 2007
Greetings, Kevin Blount.
In reply to Your message dated Friday, October 26, 2007, 08:56:24,

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

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

KB> AddType application/x-httpd-php .png

KB> Any advice?

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

can not say if AddType allowed in .htaccess or not.
Your best bet is to use header (); function and leave extension .php as is.
If You are running rented virtual server , You've little to no ability to
control document type s on server.

Other way is to ask Your hosting provider if it is possible to use filters
SAPI instead of default Apache handler SAPI. But that only available if PHP
running as Apache module AFAIK.--
Sincerely Yours, AnrDaemon <anrdaemon@xxxxxxxxxxx>


From: C. Date:   Friday, October 26, 2007
wrote in message:
Greetings, Kevin Blount.
In reply to Your message dated Friday, October 26, 2007, 08:56:24,
KB> I'm trying to create the forum favorite dynamic sig image, that's
KB> realy PHP script. I have had moderate success with .php files but when I
KB> change the extension to .png I'm prompted to download the file, rather
KB> than it rendering.
KB> My understanding is that this isn't supposed to happen, and that by
KB> adding an.htaccess file I can force .png files to be compiled/parsed/
KB> whatevered by PHP. In my .htaccess file I have:
KB> AddType application/x-httpd-php .png
KB> Any advice?
KB> I'm using heliohost.org as my host, and they basically pointed me to
KB> create the above file (as the first reply to my recent support query).
KB> Googling this I'm not seeing that I'm doing anything wrong.. so what
KB> gives?
can not say if AddType allowed in .htaccess or not.
Your best bet is to use header(); function and leave extension .php as is.
If You are running rented virtual server, You've little to no ability to
control document types on server.
Other way is to ask Your hosting provider if it is possible to use filters
SAPI instead of default Apache handler SAPI. But that only available if PHP
running as Apache module AFAIK.
--
Sincerely Yours, AnrDaemon <anrdae...@xxxxxxxxxxx>



The AddType setting determines how Apache interprets filenames and
what handler to use for them - not what gets sent to the client.

1) you do not need to have all PNG files parsed by the webserver - just
point your IMG SRC to the PHP script, and...
2) set the content type for the browser to use in a header(...) call
in your PHP

C.


From: Good Man Date:   Friday, October 26, 2007
wrote in message in

in your PHP



that is absolutely the way to go. do not mess with apache at all, use

<img src="imageDisplay.php?key=39478197">

and have imageDisplay.php use:

header("Content-type: image/png");
$im = imagecreatefrompng("test.png");
imagepng($im);http://ca.php.net/manual/en/function.imagepng.php


From: Rik Wasmus Date:   Friday, October 26, 2007
wrote in message:

wrote in message =
in

2) set the content type for the browser to use in a header(...) call
in your PHP
that is absolutely the way to go. do not mess with apache at all, use
<img src=3D"imageDisplay.php?key=3D39478197">
and have imageDisplay.php use:
header("Content-type: image/png");
$im =3D imagecreatefrompng("test.png");
imagepng($im);



Hmm, that'd be unneccessary. Unless you plan to alter the picture, =

just do a header & a readfile('test.png'); Tremendously saves memory usa=
ge.
-- =

Rik Wasmus


From: Brendan Gillatt Date:   Friday, October 26, 2007
-----BEGIN PGP SIG NED MESSAGE-----
Hash: SHA1

wrote in message:
I'm trying to create the forum favorite dynamic sig image, that's
realy PHP script. I have 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 isn't 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 do not 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=12345". 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
http://www.brendangillatt.co.uk
PGP Key: http://pgp.mit.edu:11371/pks/lookup?op=get&search=0xBACD7433
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (MingW32)

iD8DBQFHIf8FkA9dCbrNdDMRAj/RAJ4sTogymJHcE9q+u8qNVKohnCWwIgCg2pJk
kA8IGylIajuEVPq2oB5JQSE=
=Brkz
-----END PGP SIGNATURE-----


From: Good Man Date:   Friday, October 26, 2007
wrote in message in


wrote in message:
wrote in message
in



2) set the content type for the browser to use in a header(...) call
in your PHP

that is absolutely the way to go. do not mess with apache at all, use

<img src="imageDisplay.php?key=39478197">

and have imageDisplay.php use:

header("Content-type: image/png");
$im = imagecreatefrompng("test.png");
imagepng($im);
Hmm, that'd be unneccessary. Unless you plan to alter the picture,
just do a header & a readfile('test.png'); Tremendously saves memory
usage.



good one.


From: Kevin Blount Date:   Friday, October 26, 2007
wrote in message:
wrote in message in
wrote in message:
wrote in message
> in

> 2) set the content type for the browser to use in a header(...) call
> in your PHP
that is absolutely the way to go. do not mess with apache at all, use
<img src="imageDisplay.php?key=39478197">
and have imageDisplay.php use:
header("Content-type: image/png");
$im = imagecreatefrompng("test.png");
imagepng($im);
> Hmm, that'd 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.phpbasically 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


From: Rik Wasmus Date:   Friday, October 26, 2007
On Fri, 26 Oct 2007 23:39:14 +0200, Kevin Blount <kevin.blount@xxxxxxxxxxx>
wrote in message:
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


From: Kevin Blount Date:   Saturday, October 27, 2007
wrote in message:
Greetings, Kevin Blount.
In reply to Your message dated Saturday, October 27, 2007, 01:39:14,
KB> AddType application/x-httpd-php .png
Useless.
KB> RewriteEngine On
KB> RewriteRule .png /phpsigs/create-sig.php
You forgot [QSA] flag. (Query String Append)
So,
RewriteEngine On
RewriteRule \.png$ /phpsigs/create-sig.php [QSA,L]
KB> basically just redirects all .PNG requests to a single PHP script, I
KB> can then grab the file name, etc and personalize the image being
KB> returned.
--
Sincerely Yours, AnrDaemon <anrdae...@xxxxxxxxxxx>



Thanks both.

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

Cheers


From: Jerry Stuckle Date:   Saturday, October 27, 2007
wrote in message:
wrote in message:
Greetings, Kevin Blount.
In reply to Your message dated Saturday, October 27, 2007, 01:39:14,

KB> AddType application/x-httpd-php .png

Useless.

KB> RewriteEngine On
KB> RewriteRule .png /phpsigs/create-sig.php

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

So,

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

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

--
Sincerely Yours, AnrDaemon <anrdae...@xxxxxxxxxxx>
Thanks both.
I did lose the AddType in the end, but did not know about [QSA,L] -
what does that do? seems to work ok without it, but'd be good to
know what it's for.
Cheers



Try alt.apache.configuration. They can show you the correct way to do it.

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


From: Michael Fesser Date:   Saturday, October 27, 2007
.oO(Kevin Blount)

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



http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewriterule

Micha


From: Rik Wasmus Date:   Saturday, October 27, 2007
On Sat, 27 Oct 2007 21:58:25 +0200, Kevin Blount <kevin.blount@xxxxxxxxxxx>
wrote in message:

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

KB> AddType application/x-httpd-php .png

Useless.

KB> RewriteEngine On
KB> RewriteRule .png /phpsigs/create-sig.php

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

So,

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

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

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



Hmm, you'd think when doing rewrites one'd consult the manual.

http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewriterule

See 'Flags'.
--
Rik Wasmus


From: 4sak3n 0ne Date:   Saturday, October 27, 2007
wrote in message:
wrote in message:
> Greetings, Kevin Blount.
> In reply to Your message dated Saturday, October 27, 2007, 01:39:14,
> KB> AddType application/x-httpd-php .png
> Useless.
> KB> RewriteEngine On
> KB> RewriteRule .png /phpsigs/create-sig.php
> You forgot [QSA] flag. (Query String Append)
> So,
> RewriteEngine On
> RewriteRule \.png$ /phpsigs/create-sig.php [QSA,L]
> KB> basically just redirects all .PNG requests to a single PHP script, I
> KB> can then grab the file name, etc and personalize the image being
> KB> returned.
> --
> Sincerely Yours, AnrDaemon <anrdae...@xxxxxxxxxxx>
Thanks both.
I did lose the AddType in the end, but did not know about [QSA,L] -
what does that do? seems to work ok without it, but'd 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.



Next Message: Include Problem ?



Programming | Sports | Autos

copyright 2006
Valid XHTML 1.0 Transitional