2013-04-21 96 views
-1

这是代码在我的控制器......我不能老是以插入数据库映像的名称,除非在目录/上传上传/插入FILE_NAME笨:我不能插入FILE_NAME图像数据库

代码图像低于:$data[‘file_name’] = $_POST[‘file_name’];

请帮助我,因为需要快速..非常感谢你

public function edit ($id = NULL) 
{ 


    // Fetch a article or set a new one 
    if ($id) { 
    $this->data[‘article’] = $this->article_m->get($id); 
    count($this->data[‘article’]) || $this->data[‘errors’][] = ‘article could not be found’; 
    } 
    else { 
    $this->data[‘article’] = $this->article_m->get_new(); 
    } 

    // Set up the form 
    $rules = $this->article_m->rules; 
    $this->form_validation->set_rules($rules); 

    // Process the form 

    if ($this->form_validation->run() == TRUE) { 

    $data = $this->article_m->array_from_post(array(
    ‘cat_id’, 
    ‘title’, 
    ‘url’, 
    ‘body’, 
    ‘pubdate’ 
)); 


    /* 
    * upload 
    */ 
    $config[‘upload_path’] = ‘c:/wamp/www/uploads/’; 
    $config[‘allowed_types’] = ‘gif|jpg|png’; 
    $config[‘max_size’] = ‘1000’; 
    $config[‘max_width’] = ‘10240’; 
    $config[‘max_height’] = ‘7680’; 
    $field_name = “file_name”; 
    $this->load->library(‘upload’, $config); 
    if($this->upload->do_upload($field_name)){ 
    print “uploaded”; 
    die(“uploaded”); 

    } else { 
    $error = array(‘error’ => $this->upload->display_errors()); 
    print_r($error); 
    die(); 
    } 

    //end of upload 
    //insert file_name 
        $data[‘file_name’] = $_POST[‘file_name’]; 
    $this->article_m->save($data, $id); 

    } 
    // Load the view 
    $this->data[‘subview’] = ‘admin/article/edit’; 
    $this->load->view(‘admin/_layout_main’, $this->data); 
} 

回答

0

你可以尝试这样的事情

if($this->upload->do_upload($field_name)) 
{ 
    // get upload data 
    $upload_data = $this->upload->data(); 
    $data[‘file_name’] = $upload_data['file_name']; 
    $this->article_m->save($data, $id); 
    //... 
} 
else 
{ 
    //... 
} 
+1

非常感谢你<3 – WilliamShekspir 2013-04-21 04:30:13