1

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;
}
Sébastien
  • 11,860
  • 11
  • 58
  • 78
BCM
  • 665
  • 5
  • 20

1 Answers1

2

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]+)(.*)$/
Toto
  • 89,455
  • 62
  • 89
  • 125