2017-11-03 20 views
1

ニュース画像のサイズを変更するには?私は決してできなかった。Codeigniterニュース画像サイズ変更

私の問題[source_image]

私はCodeIgniterの3.1.6を使用

あなたの問題のため、この解決策を試すことができます

public function insert_news() { 
    $config['upload_path']  = 'uploads/news/'; 
    $config['allowed_types']  = 'gif|jpg|png'; 
    $config['encrypt_name']  = TRUE; 

    $this->load->library('upload', $config); 

    if ($this->upload->do_upload('news_image')) 
    { 
     $image  = $this->upload->data(); 
     $image_url = $image['file_name']; 
     $db_insert ='upload/news/'.$image_url.''; 

     $data=array(
      'news_title' => $this->input->post('news_title'), 
      'news_content' => $this->input->post('news_content'), 
      'news_image' => $db_insert, 
      'news_sef'=>sef($this->input->post('news_title')) 
     ); 

     $this->load->model('vt'); 
     $result = $this->vt->insert_news($data); 
     if ($result) { 
      echo "yes"; 
     } else { 
      echo "no"; 
     } 
    } 
} 

答えて

0

コントローラー:

コントローラ:

<?php 
public function insert_news() { 

    $config['upload_path']  = 'uploads/news/'; 
    $config['allowed_types']  = 'gif|jpg|png'; 
    $config['max_size'] = '20240000245'; 
    $config['overwrite'] = TRUE; 
    $config['encrypt_name'] = TRUE; 

    // You can change width & height 
    $imgage_width= 60; 
    $imgage_height= 60; 

    $this->load->library('upload', $config); 
    $this->upload->initialize($config); 
    if (!$this->upload->do_upload($field)) { 
     $error = $this->upload->display_errors(); 
     // uploading failed. $error will holds the errors. 
     $this->form_validation->set_message('error',$error); 
     return FALSE; 
    } else { 
     $fdata = $this->upload->data(); 
     $configer = array(
      'image_library' => 'gd2', 
      'source_image' => $fdata['full_path'], 
      'maintain_ratio' => TRUE, 
      'width'   => $imgage_width, 
      'height'   => $imgage_height, 
     ); 
     // Load Image Lib Library 
     $this->load->library('image_lib'); 
     $this->image_lib->clear(); 
     $this->image_lib->initialize($configer); 
     $this->image_lib->resize(); 
     $img_data ['path'] = $config['upload_path'] . $fdata['file_name']; 

     // uploading successfull, now do your further actions 
     $data=array(
      'news_title' => $this->input->post('news_title'), 
      'news_content' => $this->input->post('news_content'), 
      'news_image' => $img_data ['path'], 
      'news_sef'=>sef($this->input->post('news_title')) 
     ); 
     $this->load->model('vt'); 
     $result = $this->vt->insert_news($data); 
     if ($result) { 
      $this->form_validation->set_message('success',"News has been added successfully."); 
      redirect('contorller/action_name'); 
     } else { 
      $this->form_validation->set_message('error',"Error in aading news"); 
      redirect('contorller/action_name'); 
     } 
    } 
} 
?> 

私はそれがあなたを助けてくれることを願っています。

関連する問題