How do I add into the list of items allowed (gif$|jpg$|png$|jpeg$)
into the following code
$regexp = "/[0-9a-zA-z\.]/";
if (preg_match($regexp, $imageInput))
also how do I add in an exclude list e.g so stop people unploading .exe files etc.
Thanks
EDIT
I fixed it with the following code
any advice on how to make it better ?
开发者_如何学JAVA$regexp = "/^[a-zA-z0-9._-]+(gif|jpg|png|jpeg)/";
Use a positive list:
/^[0-9a-zA-z\.]+\.(gif|jpg|png|jpeg)$/
Or a negative lookahead:
/^[0-9a-zA-z\.]+\.(?!exe$)[a-z]+$/
A positive list is the safer, but more restrictive option.
change your regex to /([0-9a-zA-z\.])(gif|jpg|png|jpeg)$/
this will only allow for the extensions you have specified.
try:
$regexp = "/^[0-9a-zA-z\.]+\.(jpg|gif|png)$/";
for a stopping-pattern use '/.(exe|cmd|bat|sh)$/'
and then if(!preg_match($pattern, $text))
精彩评论