问题
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 .= '- 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