Posted by peter on 10/16/06 04:05
> Found this piece of code using preg_match to check file types during
> upload
> of files.
> $allowed_file_types = "(jpg|jpeg|gif|bmp|png)";
> preg_match("/\." . $allowed_file_types . "$/i",
> $_FILES['uploadedfile']["name"])
>
> I understand the basic preg_match but am confused as to how the string
> pattern part is working i.e.
> "/\." . $allowed_file_types . "$/i"
the regular expression equates to the following:-
"/\.(jpg|jpeg|gif|bmp|png)$/i"
basically it is saying that the string MUST contain a . (which has been
escaped by the slash) plus jpg OR jpeg OR gif OR bmp OR png. AS you see the
| means OR when enclosed in brackets like it currently is. The $ states that
the match must be at the end of the string (or in this case the file name)
and the /i staes that the match should be case insensitive.
Navigation:
[Reply to this message]
|