2017-12-08 14 views
0

画像をアップロードしてサイズを変更するには、これが必要です。私は404エラーを受け取り続け、理由を知らない。それはまた、成功のページに画像を出力すると仮定しているが、私はその脂肪を得ていない。私はcodeignighterにうまくいかず、どんな助けにも感謝しています。CodeIgniterアップロードとサイズ変更の画像

既知の問題MySQLでイメージを入れている表はimage_uploadと呼ばれています。私はこれも決して参照されていないことを知っている私は今、私は$this->load->database();を構築することを考えていることを知っている。

コントローラ

<?php 

class Upload extends CI_Controller { 

    public function __construct() 
    { 
      parent::__construct(); 
      $this->load->helper(array('form', 'url')); 
    } 

    public function index() 
    { 
      $this->load->view('upload_form', array('error' => ' ')); 
    } 

    public function do_upload() 
    { 
      $config['upload_path']   = './images/'; 
      $config['allowed_types']  = 'gif|jpg|png'; 
      $config['max_size']    = 100; 
      $config['max_width']   = 1024; 
      $config['max_height']   = 768; 

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

     $this->upload->do_upload('image'); 
    $fInfo = $this->upload->data(); // get all info of uploaded file 

    //for image resize 
    $img_array = array(); 
    $img_array['image_library'] = 'gd2'; 
    $img_array['maintain_ratio'] = TRUE; 
    $img_array['create_thumb'] = TRUE; 
    //you need this setting to tell the image lib which image to process 
    $img_array['source_image'] = $fInfo['full_path']; 
    $img_array['width'] = 113; 
    $img_array['height'] = 75; 

    $this->image_lib->clear(); // added this line 
    $this->image_lib->initialize($img_array); // added this line 
    if (!$this->image_lib->resize()) 




      if (! $this->upload->do_upload('userfile')) 
      { 
        $error = array('error' => $this->upload->display_errors()); 

        $this->load->view('upload_form', $error); 
      } 
      else 
      { 
        $data = array('upload_data' => $this->upload->data()); 

        $this->load->view('upload_success', $data); 
      } 
    } 
    } 

ビュー/フォーム

<html> 
    <head> 
    <title>Upload Form</title> 
    </head> 
    <body> 

    <?php echo $error;?> 

    <form> 

    <input type="file" name="userfile" size="20" /> 

    <br /><br /> 

    <input type="submit" value="upload" /> 

    </form> 

    </body> 
    </html> 

ビュー/ FORM_SUCCESS

<html> 
    <head> 
    <title>Upload Form</title> 
    </head> 
    <body> 

    <h3>Your file was successfully uploaded!</h3> 

    <ul> 
    <?php foreach ($upload_data as $item => $value):?> 
    <li><?php echo $item;?>: <?php echo $value;?></li> 
    <?php endforeach; ?> 
    </ul> 

    <p><?php echo anchor('upload', 'Upload Another File!'); ?></p> 

    </body> 
    </html> 
+0

'ます$ this-> upload-> do_upload( 'userfile')をアップロードした場合、コードのサイズを変更する画像を置く;'で試してみてくださいこの 。あなたのビューではあなたのファイル名はuserfileなので、あなたのコントローラではイメージとして参照しています。 –

+0

を参照https://stackoverflow.com/questions/45415265/how-do-i-resize-images-with-php-and-the-codeigniter3-framework/45417535#45417535 –

答えて

0
$this->upload->do_upload('image'); 
入力タイプのファイル名に

変更この

$this->upload->do_upload('userfile'); 

と画像が正常に

if(!$this->upload->do_upload('userfile')) 
{ 
    $fInfo = $this->upload->data(); // get all info of uploaded file 
    //for image resize 
    $img_array = array(); 
    $img_array['image_library'] = 'gd2'; 
    $img_array['maintain_ratio'] = TRUE; 
    $img_array['create_thumb'] = TRUE; 
    //you need this setting to tell the image lib which image to process 
    $img_array['source_image'] = $fInfo['full_path']; 
    $img_array['width'] = 113; 
    $img_array['height'] = 75; 

    $this->image_lib->clear(); // added this line 
    $this->image_lib->initialize($img_array); // added this line 
    $data = array('upload_data' => $this->upload->data()); 
    $this->load->view('upload_success', $data); 
} 
else 
{ 
    $data = array('upload_data' => $this->upload->data()); 
    $this->load->view('upload_success', $data); 
} 
関連する問題