This is simple,
but I am taking an entire directory listing (in PHP with dir()
), and making sure it both:
- isn't "." or "..", and
- ends in a file extension .jpg, .jpeg, .gif, or .png.
Right now I have
function isValidFile($filename) {
$dirDotExpr = "/^\.{1,2}$/"; //matches against "." and ".."
$extExpr = "/\.(jpg|jpeg|gif|png)$/i"; //checks file extension
return (1
&& ! preg_match($dirDotExpr, $filename)
&& preg_match($extExpr, $filename)
)
}
but it'd be nice to do it all in one regular expression. However, I don't know how to make sure one thing matches, and one thing doesn't--how can I accomplish this?