PHP4 で image_type_to_extension()
image_type_to_extension() という関数、PHP5 から実装されてるようなので、PHP4 でも使えるように。
<?php /** @access private */ $_image_type_define_extension = Array( IMAGETYPE_GIF => "gif", IMAGETYPE_JPEG => "jpeg", IMAGETYPE_PNG => "png", IMAGETYPE_SWF => "swf", IMAGETYPE_PSD => "psd", IMAGETYPE_BMP => "bmp", IMAGETYPE_WBMP => "wbmp", IMAGETYPE_XBM => "xbm"); function image_type_to_extension($imagetype, $include_dot = true) { global $_image_type_define_extension; if ($include_dot) { return ".".$_image_type_define_extension[$imagetype]; } else { return $_image_type_define_extension[$imagetype]; } } ?>
…おや、PHPコードの色付けが出来ないね(´・ω・`) (↑のは javascript モードで色付け)
<?php ?> をつけないと色がつかないらしい。
実際に使う場合には、上記コードを imagetype2ext.php とか適当に保存して、
<?php if (!function_exists("image_type_to_extension")) { require_once("imagetype2ext.php"); } ?>
として使うと PHP4, PHP5 両方で動いていいかもネ。