erstellen Modellnamen als Image_model in Modelle diesen Code in Ihrem Modell setzen Folder
class Image_model extends CI_Model {
public function __construct() {
parent::__construct();
$this->load->helper('url');
$this->load->library('upload');
$this->load->library('image_lib');
}
public function do_resize($filename)
{
$source_path = 'uploads/' . $filename;
//create a directory thumb in uploads set as target path
$target_path = 'uploads/thumb/thumb_'.$filename;
$config_manip = array(
'image_library' => 'gd2',
'source_image' => $source_path,
'new_image' => $target_path,
'maintain_ratio' => TRUE,
'width' => 180,
'height' => 250
);
$this->image_lib->initialize($config_manip);
$this->load->library('image_lib', $config_manip);
if (!$this->image_lib->resize()) {
echo $this->image_lib->display_errors();
die();
}
// clear //
//$this->image_lib->clear();
}
public function img_upload()
{
$config = array(
'upload_path' => "uploads",
'allowed_types' => "*",
'overwrite' => TRUE,
'max_size' => "5048000", // Can be set to particular file size , here it is 2 MB(2048 Kb)
'max_height' => "3000",
'max_width' => "3000"
);
$this->upload->initialize($config);
$this->load->library('upload', $config);
if($this->upload->do_upload()) {
$response = array('upload_data' => $this->upload->data());
//here calling the function do_resize
$this->do_resize($response['upload_data']['file_name']);
//return $response;
}
/*else{
$error = array('error'=>$this->upload->display_errors());
//print_r($error);die();
}*/
}
}
und rufen Sie die Funktionssteuerung wie dies hier ist der Controller
class your_controller extends CI_Controller {
function __construct(){
parent::__construct();
$this->load->model('image_model');
}
// here the function to save name in database
public function add() {
$data = array();
$config = array();
if(isset($_FILES)){
$config = $this->image_model->img_upload();
$file_data = $this->upload->data();
$data['image'] = $file_data['file_name'];
}
else
$data['image'] = "no-image";
// here the function in your model to save the name of image in your database
$last_id = $this->your_model->save($data);
$this->load->view('your_view');
}
den Code versuchen, lassen Sie mich wissen, dass es für Sie arbeitet oder nicht? –
Datei-Upload funktioniert gut, aber Größe ändern geben Fehler "Der Pfad zum Bild ist nicht korrekt. Ihr Server unterstützt nicht die GD-Funktion zur Verarbeitung dieses Bildtyps." –
Überprüfen Sie Ihre Server-Gd-Bibliothek aktiviert ist oder nicht \ –