public static function save_uploaded_image($image, $target_path) { if (Model_Image::validate_uploaded_image($image)) { if ($file = Upload::save($image, NULL, DOCROOT . "images/")) { Image::factory($file)->save($target_path); // Delete the temporary file unlink($file); return TRUE; } } return FALSE; }
public function action_settings() { $system_settings = ORM::factory('Systemsetting')->find_all(); if ($this->request->post()) { $values = $this->request->post(); switch ($this->request->param('id')) { case 'save': foreach ($system_settings as $setting) { // save new logo: if ($setting->name == 'logo_ext') { $image = $_FILES['logo']; if ($this->request->post('delete_logo')) { unlink(DOCROOT . 'images/logo' . '.' . $setting->value); $setting->value = NULL; } if (Model_Image::validate_uploaded_image($image)) { if (Model_Image::save_uploaded_image($image, DOCROOT . 'images/logo' . '.' . pathinfo($image['name'], PATHINFO_EXTENSION))) { // delete old logo image if the old one has different file extension than the new one if ($setting->value && $setting->value != pathinfo($image['name'], PATHINFO_EXTENSION)) { unlink(DOCROOT . 'images/logo' . '.' . $setting->value); } $setting->value = pathinfo($image['name'], PATHINFO_EXTENSION); } } } else { $setting->value = $this->request->post($setting->name); } try { $setting->save(); } catch (ORM_Validation_Exception $e) { $this->template->data["errors"] = $e->errors('models'); } } break; } if (!$this->template->data["errors"]) { $this->redirect('admin/system/settings/save'); } } else { $values = array(); foreach ($system_settings as $setting) { $values[$setting->name] = $setting->value; } } $this->template->values = $values; $this->template->templates = $this->get_templates(); $this->template->languages = ORM::factory('Language')->get_languages(); }