Reply to Re: Integrating Upload class into Zend Framework 2 (ZF2)

Re: Integrating Upload class into Zend Framework 2 (ZF2) new!
by Tom Herlihy, 9 years, 7 months ago
As the author of the original entry, I'd like to add one caution (that has been raised already in this Forum about a month ago but bears repeating) that has nothing to do with ZF2 but can prevent compilation of the Upload class, and that is that PHP 4.x and newer versions are strict about an aspect of preg_match() constructions, and refuse to compile when a hyphen in a line is not escaped (meaning preceded by a '\' character).

On about line 3014 of my copy of the Upload class, there are four cases where portions of two lines contain a '-w' that needs a '\' added before the hyphen. Here are the UNCORRECTED lines you will find that need the added '\' in four places:

// default to MIME from browser (or Flash)
if (!empty($mime_from_browser) && !$this->file_src_mime || !is_string($this->file_src_mime) || empty($this->file_src_mime)) {
  $this->file_src_mime =$mime_from_browser;
  $this->log .= '- MIME type detected as ' . $this->file_src_mime . ' by browser
';
  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 . '
';
  } else {
    $this->file_src_mime = null;
  }
}
Reply

Your reply

Name *
Email 
Title *
Text *
CAPTCHA image
Enter the code displayed on the image:
Click on the image to generate another one if it is hard to read it. The case is important