Upload odbywa się w CodeIgniterze przy pomocy jego biblioteki upload i stworzeniu miniatur za pomocą biblioteki GD2
function news_edit() { if(Site_user::_check_perm('news_edit')) { $this->load->model('News'); $id = $this->uri->segment(3); $ar = $this->News->get_news_by_id($id)->result_array(); $data['foto_url'] = $ar[0]['news_foto_url']; //------------------UPLOAD--------------------------------------- $this->load->library('upload'); $config['upload_path'] = 'system/files/'; $config['allowed_types'] = 'gif|jpg|png'; $config['max_size'] = '5000'; $config['max_width'] = '10024'; $config['max_height'] = '10768'; // przypisanie konfiguracji $this->upload->initialize($config); //------------------KONIEC--------------------------------------- $rules['streszczenie'] = "required|max_length[250]|xss_clean"; $rules['tresc'] = "required|xss_clean"; $this->validation->set_rules($rules); if ($this->validation->run() == FALSE) { $data['streszczenie']['value'] = $this->input->post('streszczenie'); $data['tresc']['value'] = $this->input->post('tresc'); $data['foto'] = $ar[0]['news_miniatura_url']; } else { $data['streszczenie']['value'] = $ar[0]['news_streszczenie']; $data['tresc']['value'] = $ar[0]['news_text']; $data['foto'] = $ar[0]['news_miniatura_url']; } $this->response['content'] = $this->load->view('elements/news_edit', $data, True); }else if (!$this->upload->do_upload()) { $this->response['content'] = 'Zmiany zapisane<META HTTP-EQUIV="Refresh" CONTENT="1; URL='.site_url('site_admin').'">'; }else if($this->upload->do_upload()) { $foto = 'system/files/'.$this->upload->data(); //-------------- Tworzenie miniatury i zmiana wielkości obrazu na 'przyjazną' Site_admin::resize($foto); // ------ zmiana samej wielkości obrazu $this->load->library('image_lib'); $config['image_library'] = 'GD2'; $config['source_image'] = $foto; $config['new_image'] = 'system/miniatury/'.$this->upload->data(); $config['create_thumb'] = FALSE; $config['maintain_ratio'] = TRUE; $config['width'] = 90; $config['height'] = 90; $this->image_lib->initialize($config); $this->image_lib->resize(); } $this->response['content'] = 'Zmiany i plik zapisane<META HTTP-EQUIV="Refresh" CONTENT="5; URL='.site_url('site_admin').'">'; } } else { $this->response['content'] = 'Niepoprawny URL'; } }else { $this->response['content'] = 'Nie masz uprawnień do tego widoku'; } $this->load->view('index', $this->response); }
funkcja do zmiany wielkości obrazu
function resize($foto) { include 'config.php'; $this->load->library('image_lib'); // konfiguracja $config['image_library'] = 'GD2'; //pobranie pliku do zmiany rozmiaru z danej lokalizacji $config['source_image'] = $foto; //zapis pliku po zmianie rozmiaru, nadpisanie pierwotnego $config['new_image'] = $foto; //jeśli true dodanie do nazwy "thumb" $config['create_thumb'] = FALSE; $config['maintain_ratio'] = TRUE; $config['width'] = $width; $config['height'] = $height; // przypisanie konfiguracji $this->image_lib->initialize($config); // wykonanie $this->image_lib->resize(); }
Nie wiem gdzie mam błąd, po zapisie ścieżka do pliku wygląda np. tak: system/files/DSC034853.JPG.JPG