Welcome Guest, Not a member yet? Register   Sign In
I can't to insert file_name image in database
#1

[eluser]Unknown[/eluser]
That`s code is in my controller... i can`t to insert name of image in database, except to upload in directory /uploads/

code for insertion file_name of image is below: $data['file_name'] = $_POST['file_name'];

please help me because needed for quickly.. thank you very much

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);
}
#2

[eluser]Sudz[/eluser]
Hi,

How can you get file_name in $_POST?

Use these lines after upload is success
Code:
$upload_data =  $this->upload->data();

$data[‘file_name’]  = $upload_data['file_name']; //this will return you file name




Theme © iAndrew 2016 - Forum software by © MyBB