class.upload.php is a powerful and mature PHP class to manage uploaded files, and manipulate images in many ways. The script is available under a GPL license.
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;
}
}
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: