2016-03-19 33 views
2

一個PHP錯誤遇到我想使用codeigniter框架上傳圖像與jquery和ajax函數。我可以看到錯誤的打擊:

嚴重性:通知消息:

未定義指數:uploadimg

文件名:型號/ upload_model.php

行號:26

我的代碼:

控制器

public function do_upload(){ 
    $this->upload->do_upload(); 
    if($this->upload_model->Doupload()){ 
     echo 1; 
    }else{ 
     echo 0; 
    } 
} 
private function set_config_option(){ 
    $config =array(
     'allowed_type' => 'gif|jpg|png|jpeg|pdf|doc|xml|zip|rar', 
     'file_size' => '100', 
     'max_width' => '1024', 
     'overwrite' => TRUE, 
     'max_height' => '768', 
    ); 
    return $config; 
} 

型號

private function set_config_option(){ 
    $config =array(
     'allowed_type' => 'gif|jpg|png|jpeg|pdf|doc|xml|zip|rar', 
     'file_size' => '2048000', 
     'max_width' => '1024', 
     'overwrite' => TRUE, 
     'max_height' => '768' 
    ); 
    return $config; 
} 

public function Doupload(){   
    $target_path = 'uploads/'; 
    $target_file = $target_path. basename($_FILES['uploadimg']['name']); 
    $base_url = base_url(); 
    $img_title = $this->input->post('imgname'); 

    $this->upload->initialize('upload', $this->set_config_option()); 
    // $img = $this->upload->do_upload();  
    } 

請幫我...

回答

1

該模型沒有收到$ _FILES對象。爲什麼要將上傳過程分成兩個文件(模型&控制器?,您在數據庫中存儲了某些內容?)。在codeiniter文檔中:https://ellislab.com/codeigniter/user-guide/libraries/file_uploading.html都在同一個文件(控制器)中。以下

嘗試的例子或嘗試在控制器添加:

$this->upload_model->Doupload($_FILES); 

,並在模型中:

public function Doupload($file){ 
    $target_path = 'uploads/'; 
    $target_file = $target_path. basename($file['uploadimg']['name']); 

我猜你加載庫:$this->load->library('upload');或自動加載配置類。希望能幫助到你!

0

添加到您的AJAX請求,如果這能幫助:) 和我你使用的形式承擔/多

xhr: function() { 
     var myXhr = $.ajaxSettings.xhr(); 
     return myXhr; 
}, 
相關問題