php - Issue with file uploader -
i have following code in controller function (this ci):
if(!empty($_files['filename']) && is_uploaded_file($_files['filename']['tmp_name'])) { $config['upload_path'] = './uploads/'; $config['allowed_types'] = 'gif|jpg|png'; $config['max_size'] = '1000'; $config['max_width'] = '1024'; $config['max_height'] = '768'; $this->load->library('upload', $config); $this->upload->overwrite = true; if ( ! $this->upload->do_upload('filename')){ $error = array('error' => $this->upload->display_errors()); var_dump($error); exit; } else { $this->upload->do_upload('filename'); $upload_info = $this->upload->data(); var_dump($upload_info); exit; } }
this should work, return no errors, , returns $upload_info
array before exit();
(exit here debugging). $upload_info
array suggests file has been passed correct path on server. folder permissions set 777 on folder.
however, file not appear on server! suggest issue might here. correct libraries have been loaded.
you call $this->upload->do_upload('filename')
twice. first time in if
, second time in else
-branch.
you should remove second $this->upload->do_upload('filename')
.
final code:
if ( ! $this->upload->do_upload('filename')){ $error = array('error' => $this->upload->display_errors()); var_dump($error); exit; } else { $upload_info = $this->upload->data(); var_dump($upload_info); exit; }
Comments
Post a Comment