Page 1 of 1
[SOLVED] Dynamic signature
Posted: Tue Apr 19, 2005 9:48 pm
by pendulum
The following code works perfectly fine:
Code: Select all
<?php
header( "Content-type: image/gif" );
$im = ImageCreate( 483, 20 ); // width, height
$red = ImageColorAllocate( $im, 255, 0, 0 );
$white = ImageColorAllocate( $im, 255, 255, 255 );
$upt = exec('uptime');
ImageString($im,3,3,3,$upt,$white);
ImageGif( $im );
ImageDestroy( $im ); // Free memory
?>
The above code is stored in thefile.php. When I request
http://example.com/thefile.php my uptime is displayed like it should be. I want to be able to link to my file from within a forum and the forum doesn't allow linking to .php files.
I gathered the work around was to create a .htaccess file with the following:
Code: Select all
<FilesMatch "e;^.*\.gif"e;>
SetHandler application/x-httpd-php
</FilesMatch>
That should make all .gif files in that directory be treated as .php files. So now all I have to do is rename thefile.php to thefile.gif and I should be able to link to it and it should work as a gif... but it doesn't
Anyone know what's wrong
Posted: Tue Apr 19, 2005 9:53 pm
by nigma
With phpbb you just use the image tags to link to the url.
Posted: Tue Apr 19, 2005 10:55 pm
by pendulum
But when I put
It doesn't work, the whole thing just appears as plain text in the signature space. It's as if it knows it's not a valid extension (.php) for an image. I tried to trick it with thefile.php?trick=yes.jpg or something but it still won't work

Posted: Tue Apr 19, 2005 11:53 pm
by pendulum
As you can see from my sig below
Posted: Wed Apr 20, 2005 12:29 am
by feyd
SetHandler is for CGI, is your PHP being run as a CGI script?
AddType is the general way:
http://httpd.apache.org/docs/mod/mod_mime.html#addtype
Posted: Wed Apr 20, 2005 7:24 am
by pendulum
I've tried with AddType just now but no go
When I request the .gif it just says "The image cannot be loaded because it contains errors" or something, but when I rename the .gif back to .php it works fine
I followed the tutorial at
http://www.phpmix.com/index.php?page=21 ... quirements but get the same error so maybe it's something to do with my GD?
Posted: Wed Apr 20, 2005 8:22 am
by vigge89
pendulum wrote:I've tried with AddType just now but no go
When I request the .gif it just says "The image cannot be loaded because it contains errors" or something, but when I rename the .gif back to .php it works fine
I followed the tutorial at
http://www.phpmix.com/index.php?page=21 ... quirements but get the same error so maybe it's something to do with my GD?
Try commenting the header()-call on the top of the script and check if PHP generates any errors.
Posted: Wed Apr 20, 2005 8:35 am
by feyd
it works perfectly for me..
Code: Select all
AddType application/x-httpd-php .gif .png .jpg .jpeg
Code: Select all
<?php
$image = 'example.jpg';
$im = imagecreatefromjpeg( $image );
ob_start();
imagejpeg($im, '', 100);
$len = ob_get_length();
$imagedata = ob_get_clean();
header( 'Content-type: image/jpeg' );
header( 'Content-length: ' . $len );
echo $imagedata;
?>
(named that way to more easily identify that it's a script, and not an image.)
outputs:

Posted: Wed Apr 20, 2005 11:03 am
by pendulum
Thanks it's working now

:):)
I configured php with jpeg support to try your example, but still couldn't get the .jpg / .gif / .png (I tried them all) to get parsed as PHP
In the end I put what you told me (the AddType thing) inside the actual httpd.conf itself and restarted Apache. It's an ok workaround but still don't really get why the .htaccess didn't work, if anyone has ideas I'm still listening
Thanks again
Posted: Wed Apr 20, 2005 12:45 pm
by vigge89
pendulum wrote:Thanks it's working now

:):)
I configured php with jpeg support to try your example, but still couldn't get the .jpg / .gif / .png (I tried them all) to get parsed as PHP
In the end I put what you told me (the AddType thing) inside the actual httpd.conf itself and restarted Apache. It's an ok workaround but still don't really get why the .htaccess didn't work, if anyone has ideas I'm still listening
Thanks again
.htaccess-files may be disabled, check out the AllowOverride directive; if it's set to "None", .htaccess -files are skipped. (
documentation)
Posted: Wed Apr 20, 2005 2:42 pm
by pendulum
Brilliant

It now works perfectly, and it was indeed set to None

:):)
Thanks