2016-10-05 6 views
0

私のコントローラ機能はcodeigniterを使って画像をアップロードするには?

<?php 
    class Image extends CI_Controller 
    { 
    public function index() 
    { 
     $this->load->view('image'); 
    } 
    public function 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->initialize($config); 
    if (!$this->upload->do_upload()) 
    { 
    $error = array('error' =>$this->upload->display_errors()); 
    $this->load->view('image',$error); 
    } 
    else 
    { 
    $data = array('upload_data' => $this->upload->data()); 
    } 
    } 
    } 
    ?> 

マイビュー機能は、これは間違っている

<?php echo $error; ?> 
    <?php 
    echo form_open_multipart('image/upload'); ?> 
    <input name="myFile" size="40" type="file" /> 
    <input type="submit" value="Upload" /> 
    </form> 
+0

注:コードシニータでは、コントローラを閉じる必要はありません '?> – user4419336

答えて

0

です。

if (!$this->upload->do_upload()) 

以下を使用してください。​​3210のフィールド名を使用する

if (!$this->upload->do_upload('myFile')) 
関連する問題