We hope you enjoy your visit.

You're currently viewing our forum as a guest. This means you are limited to certain areas of the board and there are some features you can't use. If you join our community, you'll be able to access member-only sections, and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free.


Join our community!


If you're already a member please log in to your account to access all of our features:

Username:   Password:
Add Reply
Force .PNG image to be run as PHP; Or stop .png from being cached?
Topic Started: Feb 4 2007, 02:29 PM (2,895 Views)
IceMetalPunk
Member Avatar
We are all IMPerfect. Be proud!
[ *  *  *  *  *  * ]
OK, here's my issue: I'm using PHP mixed with a Winamp plugin to create dynamic signature images that show the song/artist I'm currently listening to.

Being a dynamic image, I'd like it not to be cached. I can do that with headers in a PHP file, but as you all know, forums don't allow PHP images, meaning I need to output the image as a separate .PNG file. Now I run into the problem: If it's a .png file, how can I stop it from being cached?

So here's my question in a nutshell: Is there a way to either stop .PNG images in a forum signature not to be cached, or force PNG images to run as PHP so I can send the no-cache header with it?

-IMP ;) :)
Offline Profile Quote Post Goto Top
 
Jory
Member Avatar
Member
[ *  *  *  *  *  * ]
If your host runs Apache and has mod rewrite running, simply make a file called .htaccess with the following in it:
Code:
 
RewriteRule ^([A-Za-z0-9_\-]+).png$  $1.php[L]

or if its just one image:
Code:
 
RewriteRule ^name-of-the-image.png$  name-of-the-file.php[L]

(Just put the file in the directory the images are in.)
Offline Profile Quote Post Goto Top
 
IceMetalPunk
Member Avatar
We are all IMPerfect. Be proud!
[ *  *  *  *  *  * ]
I'm not sure if my host is running Apache or not, but I'll try it.

-IMP ;) :)

*EDIT* When I put that .htaccess file (the 1-file replacement version) inthe folder on my FTP account, all my files give this page instead of the real file:

Quote:
 
Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, webmaster@dajoob.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.
Offline Profile Quote Post Goto Top
 
Jory
Member Avatar
Member
[ *  *  *  *  *  * ]
Hmm.. *wonders what he did wrong* :S

Code:
 

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^file.png$  file.php [L]
</IfModule>


Try that.
Offline Profile Quote Post Goto Top
 
IceMetalPunk
Member Avatar
We are all IMPerfect. Be proud!
[ *  *  *  *  *  * ]
Now I don't get an error, but it still doesn't work.

I have this in the .htaccess file:

Code:
 
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^winampsigimage.png$  AMPSIG.php [L]
</IfModule>


AMPSIG.php definately exists in the same folder.

I went to MYSERVER/winampsigimage.png and got the 404 Not Found error saying "winampsigimage.png was not found".

-IMP ;) :)
Offline Profile Quote Post Goto Top
 
Ben
Member Avatar
Quantum-locked when observed.

Upload a phpinfo() page and check if mod_rewrite is present. If it isn't, that'd be the problem.
Offline Profile Quote Post Goto Top
 
IceMetalPunk
Member Avatar
We are all IMPerfect. Be proud!
[ *  *  *  *  *  * ]
Well, at least we found the problem now :lol: . Mod_rewrite is not one of the loaded modules. Is there any way to do this without using the mod_rewrite? I don't necessarily need it to redirect to a PHP page if I can get it to not cache the image file itself. Is there no way to accomplish this?

-IMP ;) :)
Offline Profile Quote Post Goto Top
 
Jory
Member Avatar
Member
[ *  *  *  *  *  * ]
You could try using something like
Code:
 
[img=http://whatever/AMPSIG.php/winampsigimage.png[/img]
.
That way, software will think your using a PNG file, but the server will serve the PHP file.

You can also just add something to the .htaccess file along the lines of
Code:
 
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/png A0
</IfModule>

It tells the server to tell the browser that PNG images expire in 0 (zero) seconds. (Don't ask me what the A before the 0 is for though. :P)
(Check if you have the expires module running the way Ben explained.)
Offline Profile Quote Post Goto Top
 
IceMetalPunk
Member Avatar
We are all IMPerfect. Be proud!
[ *  *  *  *  *  * ]
How would I get a URL like "http://whatever/AMPSIG.php/winampsigimage.png" to point to the PHP file instead of the non-existant PNG.

-IMP ;) :)
Offline Profile Quote Post Goto Top
 
Spikeman
Member
[ *  *  * ]
IceMetalPunk
February 5, 2007 07:50 PM
How would I get a URL like "http://whatever/AMPSIG.php/winampsigimage.png" to point to the PHP file instead of the non-existant PNG.

-IMP ;) :)

Only with mod_rewrite.
Offline Profile Quote Post Goto Top
 
Jory
Member Avatar
Member
[ *  *  *  *  *  * ]
No, not true.
You don't need to do anything do make that work.
Your webserver will try to go to /AMPSIG.php/winampsigimage.png, findout its not there, try to go to /AMPSIG.php, find its actually a file, and just serve that. (Note: I'm only 100% sure Apache works like this, but confident other systems do, too.)
Offline Profile Quote Post Goto Top
 
1 user reading this topic (1 Guest and 0 Anonymous)
« Previous Topic · Technology Chat · Next Topic »
Add Reply