/** * FormHandler::_handleUploads() * * Private: method to handle the uploads and image convertions * * @return void * @access public * @author Teye Heimans */ function _handleUploads() { // upload the uploaded files foreach ($this->_upload as $name) { $this->_fields[$name][1]->doUpload(); } // walk all convert actions for the upload fields foreach ($this->_convert as $field => $convertions) { // walk all convertions for this field foreach ($convertions as $action => $data) { // check if the field is an upload field and that there is a file uploaded if (in_array($field, $this->_upload)) { // is the file uploaded ? if ($this->_fields[$field][1]->isUploaded()) { // get the file which is uploaded $file = $this->_fields[$field][1]->getSavePath() . $this->_fields[$field][1]->getValue(); // check if the file exitst if (!file_exists($file)) { trigger_error("Error! Could not find uploaded file {$file}!", E_USER_WARNING); unset($file); continue; } } else { // go to the next field continue 2; } } else { if (file_exists($field)) { $file = $field; // unknown field or file! } else { trigger_error('Could not find field or file to convert: ' . $field, E_USER_WARNING); continue; } } // do the convert actions with the image (when the uploaded file is a jpg or png!) if (isset($file) && in_array(strtolower(substr($file, -4)), array('.jpg', '.png', 'jpeg', '.gif'))) { // create a new image converter $img = new ImageConverter($file); // stop when a error occoured if ($img->getError()) { trigger_error($img->getError(), E_USER_WARNING); unset($img); continue; } // walk each data (there can be more of the save convertions on the save file!) foreach ($data as $info) { // check if an error occured if ($img->getError()) { // stop converting and notice the user trigger_error($img->getError(), E_USER_WARNING); break; } switch ($action) { // merge the uploaded file with a merge image case 'merge': list($stamp, $align, $valign, $transparant) = $info; $img->doMerge($stamp, $align, $valign, $transparant); break; // resize the uploaded file // resize the uploaded file case 'resize': list($destination, $maxX, $maxY, $quality, $proportions) = $info; if (empty($destination)) { $destination = $file; } $img->setQuality($quality); $img->setConstrainProportions($proportions); $img->doResize($destination, $maxX, $maxY); break; } } unset($img); } unset($file); } } }