Trouble with AddType application/x-httpd-php .png
Trouble with AddType application/x-httpd-php .png
am 26.10.2007 06:56:24 von Kevin Blount
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?
Re: Trouble with AddType application/x-httpd-php .png
am 26.10.2007 10:47:08 von AnrDaemon
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've 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 is not 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't 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 have 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
Re: Trouble with AddType application/x-httpd-php .png
am 26.10.2007 15:02:03 von colin.mckinnon
On 26 Oct, 09:47, AnrDaemon wrote:
> 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've 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 is not 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't 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 have 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
The AddType setting determines how Apache interprets filenames and
what handler to use for them - not what gets sent to the client.
1) you don't 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.
Re: Trouble with AddType application/x-httpd-php .png
am 26.10.2007 16:31:44 von Good Man
"C. (http://symcbean.blogspot.com/)" wrote in
news:1193403723.633067.95850@o3g2000hsb.googlegroups.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
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
Re: Trouble with AddType application/x-httpd-php .png
am 26.10.2007 16:38:34 von luiheidsgoeroe
On Fri, 26 Oct 2007 16:31:44 +0200, Good Man wrote:
> "C. (http://symcbean.blogspot.com/)" wrote =
in
> news:1193403723.633067.95850@o3g2000hsb.googlegroups.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
>
>
>
> and have imageDisplay.php use:
>
> header("Content-type: image/png");
> $im =3D imagecreatefrompng("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 usa=
ge.
-- =
Rik Wasmus
Re: Trouble with AddType application/x-httpd-php .png
am 26.10.2007 16:51:49 von Brendan Gillatt
-----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=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+u8qNVKohnCWwIgCg 2pJk
kA8IGylIajuEVPq2oB5JQSE=
=Brkz
-----END PGP SIGNATURE-----
Re: Trouble with AddType application/x-httpd-php .png
am 26.10.2007 18:17:43 von Good Man
"Rik Wasmus" wrote in
news:op.t0s6ykdv5bnjuv@metallium.lan:
> On Fri, 26 Oct 2007 16:31:44 +0200, Good Man wrote:
>
>> "C. (http://symcbean.blogspot.com/)" wrote
> in
>> news:1193403723.633067.95850@o3g2000hsb.googlegroups.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
>>
>>
>>
>> and have imageDisplay.php use:
>>
>> header("Content-type: image/png");
>> $im = imagecreatefrompng("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.
Re: Trouble with AddType application/x-httpd-php .png
am 26.10.2007 23:39:14 von Kevin Blount
On Oct 26, 11:17 am, Good Man wrote:
> "Rik Wasmus" wrote innews:op.t0s6ykdv5bnjuv@metallium.lan:
>
>
>
>
>
> > On Fri, 26 Oct 2007 16:31:44 +0200, Good Man wrote:
>
> >> "C. (http://symcbean.blogspot.com/)" wrote
> > in
> >>news:1193403723.633067.95850@o3g2000hsb.googlegroups.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
>
> >>
>
> >> and have imageDisplay.php use:
>
> >> header("Content-type: image/png");
> >> $im = imagecreatefrompng("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
Re: Trouble with AddType application/x-httpd-php .png
am 27.10.2007 00:01:52 von luiheidsgoeroe
On Fri, 26 Oct 2007 23:39:14 +0200, Kevin Blount
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
Re: Trouble with AddType application/x-httpd-php .png
am 27.10.2007 11:43:47 von AnrDaemon
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
Re: Trouble with AddType application/x-httpd-php .png
am 27.10.2007 21:58:25 von Kevin Blount
On Oct 27, 2:43 am, AnrDaemon wrote:
> 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
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
Re: Trouble with AddType application/x-httpd-php .png
am 27.10.2007 23:04:55 von Jerry Stuckle
Kevin Blount wrote:
> On Oct 27, 2:43 am, AnrDaemon wrote:
>> 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
>
> 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.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@attglobal.net
==================
Re: Trouble with AddType application/x-httpd-php .png
am 27.10.2007 23:05:38 von Michael Fesser
..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.
http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewrit erule
Micha
Re: Trouble with AddType application/x-httpd-php .png
am 27.10.2007 23:06:57 von luiheidsgoeroe
On Sat, 27 Oct 2007 21:58:25 +0200, Kevin Blount
wrote:
> On Oct 27, 2:43 am, AnrDaemon wrote:
>> 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 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.
http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewrit erule
See 'Flags'.
--
Rik Wasmus
Re: Trouble with AddType application/x-httpd-php .png
am 27.10.2007 23:14:24 von 4sak3n 0ne
On Oct 27, 12:58 pm, Kevin Blount wrote:
> On Oct 27, 2:43 am, AnrDaemon wrote:
>
>
>
> > 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
>
> 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.