/** * /ajax/upload/$type * Parameter: $type - either 'RevisionUrl' or 'RevisionBackgroundImage' * Expected: $_FILES($type) * Description: Uploads an image to the server. * Returns: Dimensions and repeat rules. */ function upload($type) { $valid = true; //can we do this? if (isset($_SESSION['userrole']) && $_SESSION['userrole'] == '-1') { if ($type == 'RevisionUrl' || $type == 'RevisionBackgroundImage') { $target_path = $complocation = $this->config->item("absolute_path") . 'images/comps/'; $target_location = 'images/comps/'; //upload the file if (!$valid = validate_image_upload($type)) { echo 'fail'; exit; } $filename = date('d-m-Y-G-i-s') . '_' . basename($_FILES[$type]['name']); $filename = str_replace(" ", "_", $filename); $filename = str_replace("(", "", $filename); $filename = str_replace(")", "", $filename); $filename = implode('', explode('.', $filename, substr_count($filename, '.'))); $target_path .= $filename; $target_location .= $filename; $filename = str_replace('.', '_thumb.', $filename); $thumb_location = 'images/comps/' . $filename; if (move_uploaded_file($_FILES[$type]['tmp_name'], $target_path)) { $result = $target_location; //file upload success if ($type == "RevisionUrl") { $result = $thumb_location; //create the thumbnail move_uploaded_file($_FILES[$type]['tmp_name'], $target_path); $config['image_library'] = 'gd2'; $config['source_image'] = $target_path; $config['create_thumb'] = TRUE; $config['maintain_ratio'] = TRUE; $config['width'] = 237; $config['height'] = 303; $this->load->library('image_lib', $config); $this->image_lib->resize(); } list($w, $h) = getimagesize($target_path); if ($type == "RevisionBackgroundImage") { if ($w == $h) { //tile it $result .= ";tile"; } else if ($w < $h) { //repeat-vertical $result .= ";repeat-x"; } else if ($h < $w) { //repeat-horizontal $result .= ";repeat-y"; } } else { $result .= ";" . ($h * .2); } if ($valid == true) { echo $result; } else { echo "fail"; } } else { //file upload fail echo 'fail'; } } else { echo "fail"; } } else { echo "fail"; } }
/** * _validate * Parameters: $post - the $_POST variable * &$errors - the error list to modify * Description: Validates the client name and logo. * Returns: True or False. Also modifies &$errors. */ function _validate($post, &$errors) { //validate client name here $errors['ClientName'] = false; $errors['ClientLogo'] = false; $valid = true; if (!isset($post['ClientName']) || strlen($post['ClientName']) == 0) { $errors['ClientName'] = true; $valid = false; } //validate file upload here if(!validate_image_upload('ClientLogo')){ $errors['ClientLogo'] = true; $valid = false; } if ($valid) { return true; } else { return false; } }