-1

那是代码在我的控制器中......我不能在数据库中插入图像的名称,除了上传到目录 /uploads/

插入图像文件名的代码如下:$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);
}
4

1 回答 1

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
{
    //...
}
于 2013-04-21T04:16:09.993 回答