【问题标题】:class.upload error preg_match() [duplicate]class.upload 错误 preg_match() [重复]
【发布时间】:2015-07-06 06:16:49
【问题描述】:

我使用class.upload 0.32 版,它在我的本地主机服务器上正常工作,但在我的网络服务器上却不工作。

Web 服务器日志文件显示此错误:

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

网络服务器上的 PHP 版本: 5.4.39

本地主机上的 PHP 版本: 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;
}

【问题讨论】:

    标签: php regex preg-match


    【解决方案1】:

    你必须避开破折号:

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

    或放在字符类的末尾或开头

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

    并且点不需要转义也不需要不区分大小写:

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

    【讨论】:

      猜你喜欢
      • 2013-10-05
      • 2013-10-07
      • 2023-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多