class.upload error preg_match() [duplicate]

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-13 02:37:18

问题


I use class.upload Version 0.32 and it works correctly on my localhost server, but it does not work on my web server.

The web server log file shows this error:

PHP Warning:  preg_match(): Compilation failed: invalid range in character class at offset 7 in.

PHP version on web server: 5.4.39

PHP version on localhost: 5.5.15

if (preg_match("/^([\.-\w]+)\/([\.-\w]+)(.*)$/i", $this->file_src_mime)) {
    $this->file_src_mime = preg_replace("/^([\.-\w]+)\/([\.-\w]+)(.*)$/i", '$1/$2', $this->file_src_mime);
    $this->log .= '-&nbsp;MIME validated as ' . $this->file_src_mime . '<br />';
} else {
    $this->file_src_mime = null;
}

回答1:


You have to escape the dash:

/^([\.\-\w]+)\/([\.\-\w]+)(.*)$/i

or put it at the end or begining of the character class

/^([-\.\w]+)\/([-\.\w]+)(.*)$/i

and the dot doesn't need to be escaped nor the case insensitive :

/^([_.\w]+)\/([-.\w]+)(.*)$/


来源:https://stackoverflow.com/questions/29901765/class-upload-error-preg-match

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!