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.
more info about the class
/** * Gestion des photos de l'utilisateur */ public function photo() { $this->load->model('users_model'); $data['infos_header'] = array('titre' =>'Gestion de votre photo'); $data['vue_contenu'] = 'profil/photo'; $data['menu_accueil'] = true; $data['menu_agents'] = true; $do_upload=false; if(isset($_FILES['photo']['name'])){ $do_upload=true; } if (!$data['user'] = $this->users_model->getUser($this->session->userdata('use_id'))){ $data['vue_contenu'] = 'erreur'; $data['details'] = 'Impossible de trouver la ressource demandée ('.$this->session->userdata('use_id').').'; } else { //Nom des fichiers // $nom = 'agent_'.$data['user']->use_id.'-'.date('d-m-Y'); $nom = 'agent_'.$data['user']->use_id.'-'.date('dmY'); $extension = 'jpg'; //Début de message d'erreur $msg_erreur = 'Des erreurs se sont produites lors de l\'envoi de votre photo. '; //Traitement upload if ($do_upload) { if ($_FILES['photo']['name']==null){ $msg_erreur.='● Vous devez sélectionner une image à envoyer'; } else { //On tente de supprimer les anciennes photos @unlink(BASE_PATH.'/trombi/'.REPUPLOAD.'/miniatures/'.$data['user']->use_photo); @unlink(BASE_PATH.'/trombi/'.REPUPLOAD.'/hd/'.$data['user']->use_photo); } $this->load->library('upload_class',$_FILES['photo']); $upload_miniature=false; if ($this->upload_class->uploaded) { $this->upload_class->file_new_name_body = $nom; $this->upload_class->file_new_name_ext = $extension; $this->upload_class->image_resize = true; $this->upload_class->image_x = 170; $this->upload_class->image_ratio_y = true; $this->upload_class->file_auto_rename = false; $this->upload_class->file_overwrite = true; $this->upload_class->file_safe_name = false; $this->upload_class->image_ratio_no_zoom_out = true; $this->upload_class->process(BASE_PATH . '/trombi/'.REPUPLOAD.'/miniatures/'); if ($this->upload_class->processed) { //$this->upload_class->clean(); $upload_miniature = true; $data_user = array( 'use_id' => $this->session->userdata('use_id'), 'use_photo' => $nom.'.'.$extension ); $this->users_model->modifierUser($data_user); } else { $upload_miniature = false; $msg_erreur.= '● Echec lors du traitement de la miniature'; $data['debug_miniature'] = $this->upload_class->error; } } $upload_hd=false; if ($this->upload_class->uploaded) { $this->upload_class->file_new_name_body = $nom; $this->upload_class->file_new_name_ext = $extension; $this->upload_class->image_resize = true; $this->upload_class->image_x = 470; $this->upload_class->image_ratio_y = true; $this->upload_class->file_auto_rename = false; $this->upload_class->file_overwrite = true; $this->upload_class->file_safe_name = false; $this->upload_class->image_ratio_no_zoom_out = true; $this->upload_class->process(BASE_PATH . '/trombi/'.REPUPLOAD.'/hd/'); if ($this->upload_class->processed) { $this->upload_class->clean(); $upload_hd = true; } else { $msg_erreur.= ' ● Echec lors du traitement de la photo'; $data['debug_hd'] = $this->upload_class->error; } } //Fin upload traitement des erreurs éventuelles if (!$upload_hd || !$upload_miniature) { $this->session->set_userdata('message',array('type'=>'error','texte'=>$msg_erreur)); } else { $this->session->set_userdata('message',array('type'=>'success','texte'=>'Votre photo à été envoyée.')); redirect('profil/photo','refresh'); } } } $this->load->view('includes/theme', $data); }
I use Codeigniter from several years and add class.upload as a librairie.
Works fine.
I replace by v0.34 and I use the same code, but there is no resize.