$regex = "~^(/upload/temporary/)[0-9]{4}_[0-9]{2}_[0-9]{2}_[\w./-]+\.[a-z]{2,4}$~";
Change your delimiters to ~
When you use a delimiter for example /
, you must escape all litteral /
in your pattern otherwhise the regex engine believes that it is the end of the pattern.
Since u
is a modifier and p
isn't a modifier, you have this error because of the substring /^(/up....