php - how can i upload images in Codeigniter -
i have problem when upload images in codeigniter, have controller upload images :-
public function index() { $this->load->model('blog'); $type = "text"; if (isset($_post['post'])) { if (isset($_post['type']) && $_post['type'] == "image") { $type = "image"; } if (strlen($_files['inputupprofile']['name']) > 0) { $config['upload_path'] = './uploads/'; $config['allowed_types'] = 'gif|jpg|png'; $config['max_size'] = '2048'; $config['encrypt_name'] = true; $this->load->library('upload', $config); if (!$this->upload->do_upload('inputupprofile')) { $error = $this->upload->display_errors(); if (is_array($error)) { foreach ($error $er) { $this->errors[] = $er; } } else { $this->errors[] = $error; } } else { $updata = $this->upload->data(); $imagepath = './uploads/' . $eventpic; if (file_exists($imagepath)) { @unlink($imagepath); } $eventpic = $updata['raw_name'] . $updata['file_ext']; } } $result = $this->blog->addpost($_session['user_id'], $type, $this->input->post('post'), $eventpic); } $result = $this->blog->getposts($_session['user_id'], 0, 10); $this->template->build("home_view", array("response" => $result)); }
and view :-
<div class="textstatus"> <input id="inputupprofile" name="inputupprofile" class="inputupprofile hidefile" type="file"/> <input type="button" id="picupprofile" class="sentpic" value="addpic"> <input name="post" type="text" id="text" placeholder="message ..."> <input type="submit" id="sent" value="send"> </div> </form> </div>
when upload thee images in site error display :-
severity: notice message: undefined index: inputupprofile filename: controllers/home.php line number: 47
and
a php error encountered severity: notice message: undefined variable: eventpic filename: controllers/home.php line number: 74
and
a php error encountered severity: warning message: cannot modify header information - headers sent (output started @ d:\appserv\www\sys\system\core\exceptions.php:185) filename: core/common.php line number: 442
so problem in code.
/****************
edit :-
array ( [upload_data] => array ( [file_name] => 67429_133961013479569_306349156_n3.jpg [file_type] => image/jpeg [file_path] => d:/appserv/www/d5n/rashaqa2/uploads/ [full_path] => d:/appserv/www/d5n/rashaqa2/uploads/67429_133961013479569_306349156_n3.jpg [raw_name] => 67429_133961013479569_306349156_n3 [orig_name] => 67429_133961013479569_306349156_n.jpg [client_name] => 67429_133961013479569_306349156_n.jpg [file_ext] => .jpg [file_size] => 34.05 [is_image] => 1 [image_width] => 720 [image_height] => 540 [image_type] => jpeg [image_size_str] => width="720" height="540" ) )
i need array [file_name]
save in db, how can read this.
if($_files['nameofinputtype']['error'] == upload_err_ok) { // file uploaded $config['upload_path'] = './uploads/'; $config['allowed_types'] = 'gif|jpg|png'; $config['max_size'] = '100'; $config['max_width'] = '1024'; $config['max_height'] = '768'; $this->load->library('upload', $config); $imagen = $this->upload->do_upload(); }
Comments
Post a Comment