Just want a little sanity check. I'm working on an image manipulation script (watermarking and thumbnails) which gets the file to be processed from the URL ($GET['file']). I'm using the following check to verify that the file path is a .jp[e]g file that is (a) not above the script's directory, (b) not a url, and (c) has a ".jp[e]g" suffix. I'm just wondering if anyone can think of any other nasty thing I should check for that a hacker might want to stick in there should he be aware of the script's URL?
$file = $_GET['file'];
if (preg_match('#(^/|\.\.|(f|ht)tps?://)#i', $file) or
!preg_match('#\.jpe?g$#i', $file))
{
hdr404(); // disallowed path, outta here...
}
(hdr404() simply sends a 404 header and exits.)