Web Programming PHP Image Class: Function getExtension

Image Class: Function getExtension

nathanael PHP May 30, 2007

function getExtension($filename){
$dot = substr (strrchr ($filename, "."), 1);
return $dot;

This is a very small, simple fucntion. it returns the file extension of a given file (in jpg format; with no .). All I use this for is the resize function. If you try to resize a .pdf file, you will get an error, so I have this check to make sure the file extension is ok. you can also call this function outsite of the resize function like this:

$ext = $obj_images->getExtension("./test/img.jpg");
echo $ext;

Thats really all there is for the function, you see how we use it in the rezise function in the next section. Sooo, next function:

subscribe to newsletter