views:

354

answers:

2

Hello.

I'm making a dynamic image for a forum that doesn't allow dynamic images.

I tried using .htacess to redirect all *.png files to image.png... which works perfectly, but from here I can't seem to be able to get the filename of the .png that was requested to generate the content.

is there a way to do this?

For example...

user puts in banana.png

htaccess forwards to image.php

I need a way of getting that banana into my php script.

Using $_SERVER['REQUEST_URI'] and $_SERVER["SCRIPT_NAME"] just returns that of the PHP file.

Is there a way of redirecting it to image.php?=bananana for example?

Any help would be highly appreciated. Kind Regards

+1  A: 

Try this one. You should be able to access the image path at $_GET['image']. Added ability to preserve existing query string if need be, (but the image key would obviously be overridden).

If you are still getting 404, I don't know what to say. I tested this and it works for me.

RewriteRule ^(.*\.png)$ image.php?%{QUERY_STRING}&image=$1 [L]
eyelidlessness
Hi eyelidlessness, I just get a 404 Not found error message for all PNG files with that code =(
Lisa
how odd, still cant seem to get it to work =(I guess I just have a dodgy server? Thank you for your help anyway =DI managed to get.../img.php?id=/ipboard/dynaimage/989890.pngfrom...RedirectMatch 301 ^(.*\.png)$ /img.php?id=$1
Lisa
Huh. Maybe mod_rewrite is not enabled? Or maybe my rewrite should go to /img.php. I dunno. If it works, it works. Toodles.
eyelidlessness
+1  A: 
RewriteEngine on
RewriteRule ^(.+)\.png$ image.php?file=$1 [L,QSA]

If this doesn't work, you likely don't have mod_rewrite enabled.

ceejayoz